简体   繁体   English

jQuery从完全不透明淡入0.2

[英]jquery fading in from full opacity to 0.2

when the page loads i would like the span overlay to fade in from full #000 to opacity 0.2 and then stay at 0.2 to which when i hover it goes to opacity 0 当页面加载时,我希望跨度叠加层从完整的#000渐变为不透明0.2,然后保持在0.2处,当我将其悬停时,它变为不透明0

this is the code i have at the moment 这是我目前的代码

$(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 });
    });
});

here is an example 这是一个例子

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

Something like this? 像这样吗

$(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);
    });
});

对我来说,它似乎运行得很好(并且效果很好:D)。对不起,但是,您的问题是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM