jquery hide div

问题描述:

我希望有人能帮助我。我发现这个jQuery脚本使用AJAXjquery hide div

$(document).ready(function(){ 
    //References 
    var sections = $("#menu li"); 
    var loading = $("#loading"); 
    var content = $("#content"); 

    //Manage click events 
    sections.click(function(){ 
     //show the loading bar 
     showLoading(); 
     //load selected section 
     switch(this.id){ 
      case "home": 
       content.slideUp(); 
       content.load("/includes/content.asp", hideLoading); 
       content.slideDown(); 
       break; 
      //case "news": 
      // content.slideUp(); 
      // content.load("sections.html #section_news", hideLoading); 
      // content.slideDown(); 
      // break; 
      case "interviews": 
      content.slideUp(); 
      content.load("/includes/test1.asp", hideLoading); 
      content.slideDown(); 
      break; 
      case "external": 
       content.slideUp(); 
       content.load("/includes/test.asp", hideLoading); 
       content.slideDown(); 
       break; 
      default: 
       //hide loading bar if there is no selected section 
       hideLoading(); 
       break; 
     } 
    }); 

    //show loading bar 
    function showLoading(){ 
     loading 
      .css({visibility:"visible"}) 
      .css({opacity:"1"}) 
      .css({display:"block"}) 
     ; 
    } 
    //hide loading bar 
    function hideLoading(){ 
     loading.fadeTo(1000, 0); 
    }; 
}); 

加载内容到一个步伐,这行代码是在主页上

<div id="loading"> 
    <div align="center"><img src="/css/images/loading.gif" alt="Loading" /></div> 
</div> 

我需要隐藏加载图片时,我的页面加载(隐藏DIV ID =“loading”)当页面加载时它不隐藏,当我点击一个链接将内容加载到我的页面时div有移动我的内容...

任何想法如何在加载div完成时隐藏div?

感谢

$(document).ready(function(){ 
    //References 
    var sections = $("#menu li"); 
    var loading = $("#loading").hide(); // Hide the loading image on page load 
    var content = $("#content"); 

而且不是使用.fadeTo()使用.fadeOut()让您加载影像将会被隐藏动画结束。

function hideLoading(){ 
    loading.fadeOut(1000); 
}; 

而且,改善您的showLoading()可能是:

function showLoading(){ 
    loading.show(); 
     // or if you want it animated 
     // loading.fadeIn(200); 
} 
+0

您好帕特里克 - 感谢您的反馈,它解决了50问题的百分比,当页面加载时,现在隐藏图片加载,但div仍然在那里移动我的内容... – 2010-07-08 14:30:57

+0

@杰拉德 - 嗨。我刚刚更新了我的答案。 :o)使用'fadeOut()'而不是'fadeTo()'。实际上,你可以通过类似的方式改进'showLoading()'函数。我会更新。 – user113716 2010-07-08 14:31:52

+0

谢谢帕特里克我已经应用了你所建议的解决方案,它的工作原理是100% - 非常感谢! – 2010-07-08 17:11:20

你只需拨打:

$("#loading").hide(); 

呼叫这对$(document).ready

你可能想尝试以下操作:

$(document).ready(function(){ 
    $('#loading').css('display','none'); /*If you want the div to appear as if it never existed*/ 
    $('#loading').css('visibility','hidden'); /*If you want the div to be 'hidden' but keep the space that it occupies.*/ 
});