开发者

How to get my div to fade out with jQuery on page load?

开发者 https://www.devze.com 2023-01-10 11:24 出处:网络
I\'m brand new to jQuery (and javascript in general). I\'ve been meaning to use it/learn it for some time, and nows the time.

I'm brand new to jQuery (and javascript in general). I've been meaning to use it/learn it for some time, and nows the time.

So I'开发者_JAVA百科m going to use jQuery on this page to fade out the "under construction" warning at the top of the page on load. But I'm unfamiliar with any of the functions or selectors to use.

I found this basic article at jQuery which has a demo that seems to work perfect for what I'm doing, only it's set up to fade out on click.

What do I need to change to get it to fade out after a few seconds once the page has loaded, and can you point me where to look to find out more about those type of functions (specifically on jQuery's site, if you're familiar). And please don't say, "In the documentation." I'm a noob but not a dummy, thanks. I'm just trying to learn more about that particular area of the syntax responsible for functions for now (if that's what they're called).


New to jQuery 1.4 is the delay method. Using it for this purpose:

$("#myDiv").delay(3000).fadeOut("slow");


$(document).ready(function() {
   window.setTimeout("fadeMyDiv();", 3000); //call fade in 3 seconds
 }
)

function fadeMyDiv() {
   $("#myDiv").fadeOut('slow');
}


Hey, the site looks cool. This should do it for you.

$(document).ready(function() {
    setTimeout(fade, 2000);
}

function fade(){
   $("#tempwarning").fadeOut(1000);
}


Here's a complete example.

Just paste this into an html file and save it.

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.4.2.min.js" />
    <script>
    $(document).ready(function(){   
        window.setTimeout('fadeout();', 3000);
    });

    function fadeout(){
        $('#tempwarning').fadeOut('slow', function() {
           // Animation complete.
        });
    }

    </script>
</head>
<body>
    <div id="tempwarning">

        <div class="wrap">

            <span class="warning-icon">!</span>

            <p>
                Oops! Please pardon my appearance. I'm still <a href="http://graphicriver.net/item/under-construction-graphic/53758?ref=jglovier">under development</a>. Please visit often.
            </p>

        </div>

    </div>
</body>
</html>

EDIT:

This line of code:

 $(document).ready(function() { }); 

Waits for the page to load before executing anything inside it.


$(document).ready(function(){
    setTimeout(function(){ $("#tempwarning").fadeOut(); }, 2000);
});


<script>
$(document).ready(function(){   
    window.setTimeout('fadeout();', 1000);
});

function fadeout(){
    $('.loader').fadeOut('fast', function() {
       // Animation complete.
    });
}

</script>

Perfect for a LoadingPage

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号