繁体   English   中英

添加CSS后如何运行jquery函数

[英]How to run a jquery function after i added css

我有这条线:

$('body>header:last a,body>header:last div,body>header:last h1').css("-webkit-transition", "opacity 0.5s ease-in");

我希望其余的javascript在添加样式之后运行。 我目前使用计时器

setTimeout(function () {
                    $('body>header:not(:last),body>footer:not(:last),body>#content:not(:last)').remove();                   
                    $('body>header,body>footer,body>#content').removeAttr('style'); },1000);

但是不知何故,在执行计时器时而不是在计时器执行时添加了css。 知道为什么会这样吗? 如果没有,可以在添加css后强制超时功能运行

使第一个代码在其自己的函数中运行,并为其提供回调函数

function addStyle(callback)
{
    $('body>header:last a,body>header:last div,body>header:last h1').css("-webkit-transition", "opacity 0.5s ease-in");

    if (typeof callback !== 'undefined') callback();
}

然后这样称呼它:

addStyle(function(){

    // Do other stuff here after css is added...

});

您可以在loadPage外部声明setTimeout,然后在document.ready中调用它吗?

找到答案的家伙! 我不是jquery问题,而是css3技巧。

为了制作动画,必须将元素的不透明度设置为1。这种情况是在1秒钟的延迟之后发生的。 我没有不理解2之间的联系,但现在我知道了。 所以我所做的就是更改此:

$('body>header:last a,body>header:last div,body>header:last h1').css({'-webkit-transition': 'opacity 0.5s ease-in','opacity':'1'});

我简单地将opacity:1添加到之前为0的css中,以便开始过渡。

抱歉让您头疼,无论如何,谢谢:)

暂无
暂无

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

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