jquery元素到javascript元素

jquery元素到javascript元素,javascript,jquery,css,css-animations,Javascript,Jquery,Css,Css Animations,因此,我正在使用css动画,在javascript中,您可以使用以下代码启动和停止一个动画: element.style.webkitAnimationPlayState="paused"; element.style.webkitAnimationPlayState="running"; 现在我有了一些Jquery,看起来是这样的: $(".info").click(function(){ $it = $(this).closest(".thing"); //how can

因此,我正在使用css动画,在javascript中,您可以使用以下代码启动和停止一个动画:

element.style.webkitAnimationPlayState="paused";
element.style.webkitAnimationPlayState="running";
现在我有了一些Jquery,看起来是这样的:

$(".info").click(function(){
    $it = $(this).closest(".thing");
    //how can I use the above javascript on the specified jquery element?
});
我的问题在代码中的注释中这可能吗?怎么做?


如果要暂停动画(然后从暂停点继续),可以使用此CSS属性切换动画的播放状态:

.paused {
   -ms-animation-play-state:paused;
   -o-animation-play-state:paused;
   -moz-animation-play-state:paused;
   -webkit-animation-play-state:paused;
  animation-play-state: paused;
}
然后可以使用jquery切换暂停的类:

$(".info").click(function(){
    $it = $(this).closest(".thing");
    $it.toggleClass("paused");
});

这里,
$lt
是一个jQuery包装对象,而不是dom元素引用,您可以使用索引0获取dom元素引用

$it[0].style.webkitAnimationPlayState="running"; 
演示:

或者使用jQuery提供的设置样式值

$it.css('webkitAnimationPlayState', 'running'); 

演示:

$它是一个数组。如果它只包含一个元素,你可以

$it[0].style.webkitAnimationPlayState="running"; 
如果$it包含多个元素,并且您希望将此样式应用于每个元素

$($it).each(function(){this.style.webkitAnimationPlayState="running";});
您可以使用元素来执行此操作

$(".info").click(function(){
    var $it = $(this).closest(".thing");
    alert($it.text());
    $it.css({"webkitAnimationPlayState":"running"}); 
});

我不想暂停动画…谢谢…现在看看这把小提琴:。。。为什么暂停不起作用?@RyanSaxe它应该像在包装器元素中调用
on
方法一样。。。它也不应该在点击处理程序中…你给我的JSFIDLE不起作用。。。