Basic jquery question, fade in content after 1-2 seconds

Discussion in 'jQuery' started by js09, Jul 26, 2009.

  1. #1
    I'm looking to modify this code in order to have my content auto fade in after about 1-2 seconds. currently, it only fades in when you move the mouse cursor over the content.


    $(document).ready(function(){
    $(".latest_img").fadeTo("slow", 0.3);
    $(".latest_img").hover(function(){
    $(this).fadeTo("slow", 1.0);
    },function(){
    $(this).fadeTo("slow", 0.3);
    });
    });
    
    Code (markup):
    thx for any help!
     
    js09, Jul 26, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    try this:
    var foo = setTimeout(function() {
        $(".latest_img").fadeTo("slow", 1);
    }, 2000); // 2 seconds
    
    $(".latest_img").hover(function() {
        // remove auto fade if the mouseover takes place first
        clearTimeout(foo);
        $(this).fadeTo("slow", 1.0);
    }, function() {
        $(this).fadeTo("slow", 0.3);
    });
    
    PHP:
     
    dimitar christoff, Jul 26, 2009 IP