Fade Out/In Div on Page Load

℡╲_俬逩灬. 提交于 2019-12-11 19:07:29

问题


When a new page loads on my site, I want the main content (located within a div inside the body,as to exclude the footer and header) of the old page to fade out, and the main content of the new page to fade in, all by using jQuery. My code is basically:

<html>

 <head> -random header info- (also where I figured the jQuery would go?)
 </head>

  <body>

   <div id="header">
   </div>

   <div id="main"> - main content of site - 
   </div>

   <div id="footer"> 
   </div>

  </body>

</html> 

I only want the fade out and in to affect: <div id="main"> how can I do this?


回答1:


Try this, make sure to include jquery library as well.

$(document).ready(function(){
    $("div#main").fadeOut();
});

To fade in, add style="display:none" to your div, and change fadeOut() to fadeIn().




回答2:


In your document.ready:- Fadeout:-

$('#main').fadeOut('slow');

FadeIn:-

$('#newcontent').fadeIn('slow');


来源:https://stackoverflow.com/questions/15561550/fade-out-in-div-on-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!