简体   繁体   English

将元素添加到dom并使用jquery应用类不会应用css3转换

[英]Adding element to dom and applying class with jquery doesn't apply css3 transition

First, my demo is here: JsFiddle . 首先,我的演示在这里: JsFiddle

I'm trying to add an element to the dom with jquery and then make it do some css3-transition animations. 我正在尝试用jquery向dom添加一个元素,然后让它做一些css3-transition动画。 I'm not sure why it doesn't work the first time it's appended. 我不确定为什么它第一次附加时不起作用。 I click the button and it appends but when I addClass to the div it doesn't animate it. 我单击按钮它会附加但是当我将addClass添加到div时它不会为它设置动画。 It simply just applies the css without animations. 它只是在没有动画的情况下应用css。

Any idea of why this doesn't work for the div.addClass('test') right after the element is appended? 在添加元素之后,任何想法为什么这对div.addClass('test')

May be the same as Trigering a CSS3 Transition with adding a class with Jquery 可能与使用Jquery添加类的Trigering CSS3 Transition相同

But I'm curious if there was any new solutions to it. 但我很好奇是否有任何新的解决方案。 That one didn't seem to really get answered. 那个似乎没有真正得到回答。

The suggestion from your article seems to somewhat work, i see your commented out code and it looked like the timeout needed to be lower or it needed to be applied with the class selector and not the variable / div. 你的文章的建议似乎有点工作,我看到你注释掉的代码,看起来需要更低的超时或者需要应用类选择器而不是变量/ div。 Really no idea why it works, I just fiddle. 真的不知道它为什么会起作用,我只是小提琴。

I changed a line in your fiddle to reflect the suggestion from that article. 我改变了你的小提琴中的一行,以反映该文章的建议。

setTimeout(function(){$('.article').addClass('test').removeClass('test2');}, 0)

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

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