为什么单击时的关键帧动画只触发一次
Why does keyframes animation on click only trigger once?
下面是我的代码,关键帧动画仅在第一次单击时发生。有什么想法吗?
解决了,请参阅下面的答案
JQUERY:
$(".audioplayer-playpause").click(function(){
$('.audioplayer-playpause').css({
//for firefox
"-moz-animation-name":"playPausePulse",
"-moz-animation-duration":"0.1s",
"-moz-animation-iteration-count":"1",
"-moz-animation-fill-mode":"forwards",
//for safari & chrome
"-webkit-animation-name":"playPausePulse",
"-webkit-animation-duration":"0.1s",
"-webkit-animation-iteration-count":"1",
"-webkit-animation-fill-mode":"forwards",
});
});
.CSS:
@-moz-keyframes playPausePulse /*--for webkit--*/{
0% {background-color: rgba(0, 0, 0, 0.05);}
50% {background-color: rgba(0, 0, 0, 0.1);}
100% {background-color: rgba(0, 0, 0, 0.05);}
}
@-webkit-keyframes playPausePulse /*--for webkit--*/{
0% {background-color: rgba(0, 0, 0, 0.05);}
50% {background-color: rgba(0, 0, 0, 0.1);}
100% {background-color: rgba(0, 0, 0, 0.05);}
}
这非常相关,但我访问了两个参考链接,但找不到有效的解决方案:多次单击时运行关键帧动画
任何帮助将不胜感激。
谢谢。托马斯。
我找到了一个解决方案:
我添加了一个侦听器,最后给元素一个新的/重置动画
简讯
$(".audioplayer-playpause").click(function(){
$('.audioplayer-playpause').css({
//for firefox
"-moz-animation-name":"playPausePulse",
"-moz-animation-duration":"0.1s",
"-moz-animation-iteration-count":"1",
"-moz-animation-fill-mode":"forwards",
//for safari & chrome
"-webkit-animation-name":"playPausePulse",
"-webkit-animation-duration":"0.1s",
"-webkit-animation-iteration-count":"1",
"-webkit-animation-fill-mode":"forwards",
});
});
$(".audioplayer-playpause").bind('oanimationend animationend webkitAnimationEnd', function() {
$(".audioplayer-playpause").css({
'-moz-animation-name': 'playPausePulseReset',
'-webkit-animation-name': 'playPausePulseReset',
});
});
.CSS
@-moz-keyframes playPausePulse /*--for webkit--*/{
0% {background-color: rgba(0, 0, 0, 0.05);}
50% {background-color: rgba(0, 0, 0, 0.1);}
100% {background-color: rgba(0, 0, 0, 0.05);}
}
@-webkit-keyframes playPausePulse /*--for webkit--*/{
0% {background-color: rgba(0, 0, 0, 0.05);}
50% {background-color: rgba(0, 0, 0, 0.1);}
100% {background-color: rgba(0, 0, 0, 0.05);}
}
@-moz-keyframes playPausePulseReset /*--for webkit--*/{
0%, 100% {
background-color: rgba(0, 0, 0, 0.05);
}
}
@-webkit-keyframes playPausePulseReset /*--for webkit--*/{
0%, 100% {
background-color: rgba(0, 0, 0, 0.05);
}
}
像这样使用 .on() 或 .live()
$(".audioplayer-playpause").on('click',function(){});
或者像这样
$(document).on('click',".audioplayer-playpause",function(){});
所以你的代码将是
$(document).ready(function(){
$(".audioplayer-playpause").on('click',function(){
$(this).css({
//for firefox
"-moz-animation-name":"playPausePulse",
"-moz-animation-duration":"0.1s",
"-moz-animation-iteration-count":"1",
"-moz-animation-fill-mode":"forwards",
//for safari & chrome
"-webkit-animation-name":"playPausePulse",
"-webkit-animation-duration":"0.1s",
"-webkit-animation-iteration-count":"1",
"-webkit-animation-fill-mode":"forwards",
});
});
});
相关文章:
- 单击仅在第二次单击后有效
- 删除确认对话框在第一次单击时不起作用
- 在单击事件中,第一次单击时激发代码一次,其余代码在所有单击时运行
- 一次点击,两次'单击'事件已启动
- 单击一次以静音,另一次单击可取消静音
- 一次单击一下即可在句子中显示大字符串
- 如何在函数中添加一次单击事件
- 让窗口在一次单击触发两个页面重定向后保持焦点
- 我的 jQuery 滑块运行良好,但存在错误,它有时不会在下次或上一次单击时显示图像
- 元素上的多次单击绑定仅在挖空.js中执行一次
- 向同一按钮添加两次单击事件只能工作一次
- 单击时将html存储到变量中,从DOM中删除,然后在另一次单击时将其放回
- 向下滑动一次单击标签不会滑动
- Jquery获取最近一次单击的属性ID
- jquery单击事件在一次单击中执行多次
- JQuery通过另一次单击的代码单击
- 对于动态创建的元素,只绑定一次单击事件
- JQuery三按钮单击事件执行一次单击
- 每隔一次单击Internet Explorer中的链接都不起作用
- 事件(单击)如何通过另一次单击一次又一次地触发