2011-02-09 47 views
0

在頁面加載時我想的跨度覆蓋從全#000淡入不透明0.2 ,然後停留在0.2到時我將鼠標懸停它變爲不透明0jQuery的從完全不透明衰落至0.2

這是代碼,我此刻

$(function() { 
    $('ul li a').append('<span id="load"></span>'); 
    $('span').css('display', 'block').fadeOut(3400); 

    $('span') .animate ({ 
      "opacity" : .2 
    }); 

    $('span') .hover(function() { 
     $ (this) .animate ({"opacity": 0}); 
    }, function() { 
     $(this).stop() .animate ({"opacity": .2 }); 
    }); 
}); 

這裏有一個例子

http://satbulsara.com/experiment-04/

回答

1

是這樣的嗎?

$(function() { 

    var animateDuration = 2000; 

    /* this is actually a no-no since you should only use an ID for a 
     single element on the page - you should use a class instead */ 
    $('ul li a').append('<span id="load"></span>'); 

    /* I'm not sure I understood you correctly, but it sounds like 
     you want to do something like: */ 
    $('span').css({ 
     display:'block', 
     opacity: 0.9 
    }).animate({ 
     opacity: 0.2 
    }, animateDuration); 
    /* It causes the element to have an opacity 0f 0.9 when the 
     page loads and then start animating to opacity 0.2 */ 


    $('span') .hover(function() { 
     $ (this) .animate ({"opacity": 0}, animateDuration); 
    }, function() { 
     $(this).stop() .animate ({"opacity": .2 }, animateDuration); 
    }); 
}); 
+0

涼爽的作品,有沒有什麼辦法來設置每個跨度timout? – sat 2011-02-09 16:12:05

0

對我來說,似乎工作完美(和做得很好:D).. 對不起,但是,你的問題是什麼?

+0

我想有覆蓋範圍從0.9到0.2之後,還能夠使用懸停效果 – sat 2011-02-09 15:36:41