使用 jquery 触发 css3 关键帧
我编写了一个关键帧动画:
@-webkit-keyframes cubemove {
0% {-webkit-transform: translateZ(-194px) rotateY(0deg);}
20% {-webkit-transform: translateZ(-194px) rotateX(-180deg);}
40% {-webkit-transform: translateZ(-194px) rotateX(-90deg);}
60% {-webkit-transform: translateZ(-194px) rotateX(90deg);}
80% {-webkit-transform: translateZ(-488.5px) rotateY(90deg);}
90% {-webkit-transform: translateZ(-488.5px) rotateY(-90deg);}
100% {-webkit-animation-play-state:paused;}
}
.cubebox {
-webkit-animation: cubemove 30s ease-in-out 5s 1 normal;
}
我想在使用以下 html 和查询代码制作的矩形上运行此动画:
<figure id="box">
<img src="/images/cube/step1.jpg"/>
<img src="/images/cube/step2.jpg"/>
<img src="/images/cube/step3.jpg"/>
<img src="/images/cube/step4.jpg"/>
<img src="/images/cube/step5.jpg"/>
<img src="/images/cube/step6.jpg"/>
</figure>
<button class="commencer">Start</button>
<script type="text/javascript">
jQuery.noConflict();
$(document).ready(function(){
$('.commencer').click(function(){
$('#box').addClass('cubemove');
});
$('.commencer').click(function(){
$(this).removeClass('cubemove');
});
});
</script>
问题是,当我单击按钮时,什么也没有发生。我不太擅长 jquery 所以这可能是问题所在。
非常感谢您的帮助!
马特
I wrote a keyframe animation:
@-webkit-keyframes cubemove {
0% {-webkit-transform: translateZ(-194px) rotateY(0deg);}
20% {-webkit-transform: translateZ(-194px) rotateX(-180deg);}
40% {-webkit-transform: translateZ(-194px) rotateX(-90deg);}
60% {-webkit-transform: translateZ(-194px) rotateX(90deg);}
80% {-webkit-transform: translateZ(-488.5px) rotateY(90deg);}
90% {-webkit-transform: translateZ(-488.5px) rotateY(-90deg);}
100% {-webkit-animation-play-state:paused;}
}
.cubebox {
-webkit-animation: cubemove 30s ease-in-out 5s 1 normal;
}
I want to run this animation on a rectangle I made using the following html and query code code:
<figure id="box">
<img src="/images/cube/step1.jpg"/>
<img src="/images/cube/step2.jpg"/>
<img src="/images/cube/step3.jpg"/>
<img src="/images/cube/step4.jpg"/>
<img src="/images/cube/step5.jpg"/>
<img src="/images/cube/step6.jpg"/>
</figure>
<button class="commencer">Start</button>
<script type="text/javascript">
jQuery.noConflict();
$(document).ready(function(){
$('.commencer').click(function(){
$('#box').addClass('cubemove');
});
$('.commencer').click(function(){
$(this).removeClass('cubemove');
});
});
</script>
The thing is that nothing happen when I click on the button. I am not very good with jquery so that might be the problem.
Thank you very much for your help!
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在添加单击事件以向同一按钮添加和删除类。最终结果是该元素将处于与启动时相同的状态。尝试使用分隔按钮来开始。
You're adding click events to both add and remove the class to the same button. The net result is that the element will be in an identical state to when it started. Try using to separate buttons to start with.
我发现了问题。这是一个查询冲突问题。
我使用了以下代码并且它有效。
I found the problem. It was a query conflict problem.
I used the following code and it worked.
我建议你也尝试这个 jquery 插件,它可以动态地将 css3 动画添加到元素和一堆额外的东西: https: //github.com/krazyjakee/jQuery-Keyframes
I recommend you also try this jquery plugin which can dynamically add css3 animations to elements and a bunch of extra stuffs: https://github.com/krazyjakee/jQuery-Keyframes