jquery从完全不透明度渐渐消失到0.2

时间:2011-02-09 15:18:08

标签: javascript jquery

当页面加载时,我希望跨度叠加从完整#000淡入到不透明度0.2 然后保持在0.2,当我悬停时,它会进入不透明度0

这是我目前的代码

$(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/

2 个答案:

答案 0 :(得分: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);
    });
});

答案 1 :(得分:0)

对我来说它似乎完美无缺(并且做得很好:D).. 对不起,但是,你的问题是什么?