admin管理员组文章数量:1026989
Hi I have been trying to figure out how to change my css3 -webkit-animation-play-state from paused to running by clicking on another div. Does any one know how I would do this?? Im assuming I would need to use JavaScript.
Hi I have been trying to figure out how to change my css3 -webkit-animation-play-state from paused to running by clicking on another div. Does any one know how I would do this?? Im assuming I would need to use JavaScript.
Share Improve this question asked Apr 15, 2012 at 0:08 JohnJohn 111 silver badge2 bronze badges2 Answers
Reset to default 3I don't think you're able to do it unless you use JavaScript. Using JavaScript, you would have to fetch the style.webkitAnimationPlayState
of the element you wish to change. If it's an empty string, then it is set to the inital value, which is "running"
.
In the example code, clickDiv
is the div you click and animationDiv
is the div whose webkit-animation-play-state
is getting changed:
clickDiv.addEventListener("click", function(){
if (animationDiv.style.webkitAnimationPlayState == "paused") {
animationDiv.style.webkitAnimationPlayState = "running";
}else if(animationDiv.style.webkitAnimationPlayState == "running" || animationDiv.style.webkitAnimationPlayState == ""){
animationDiv.style.webkitAnimationPlayState = "paused"; // assuming you want to toggle
}
console.log(animationDiv.style.webkitAnimationPlayState);
})?
Demo Here
look at http://jsfiddle/JCzpd/37/
var animationDiv = document.getElementById("aD");
var clickDiv = document.getElementById("cD");
clickDiv.addEventListener("click", function(){
if (animationDiv.style.animation == "") {
animationDiv.style.animation = " anim .5s forwards";
//animationDiv.style.animation = " anim running .1s infinite";
}else{
animationDiv.style.animation = ""; // assuming you want to toggle
}
});
#aD{ background-color:green;
height:30px;
margin:2px 0 5px 2px;}
#cD{background-color:blue;}
@keyframes anim{
0%{ background-color:green;}
100%{ background-color:red;}
}
#aD:hover{animation: anim 1s infinite;
cursor:pointer;}
<div id="aD">animated div</div>
<div id="cD">click div</div>
change mented line for different anim
Hi I have been trying to figure out how to change my css3 -webkit-animation-play-state from paused to running by clicking on another div. Does any one know how I would do this?? Im assuming I would need to use JavaScript.
Hi I have been trying to figure out how to change my css3 -webkit-animation-play-state from paused to running by clicking on another div. Does any one know how I would do this?? Im assuming I would need to use JavaScript.
Share Improve this question asked Apr 15, 2012 at 0:08 JohnJohn 111 silver badge2 bronze badges2 Answers
Reset to default 3I don't think you're able to do it unless you use JavaScript. Using JavaScript, you would have to fetch the style.webkitAnimationPlayState
of the element you wish to change. If it's an empty string, then it is set to the inital value, which is "running"
.
In the example code, clickDiv
is the div you click and animationDiv
is the div whose webkit-animation-play-state
is getting changed:
clickDiv.addEventListener("click", function(){
if (animationDiv.style.webkitAnimationPlayState == "paused") {
animationDiv.style.webkitAnimationPlayState = "running";
}else if(animationDiv.style.webkitAnimationPlayState == "running" || animationDiv.style.webkitAnimationPlayState == ""){
animationDiv.style.webkitAnimationPlayState = "paused"; // assuming you want to toggle
}
console.log(animationDiv.style.webkitAnimationPlayState);
})?
Demo Here
look at http://jsfiddle/JCzpd/37/
var animationDiv = document.getElementById("aD");
var clickDiv = document.getElementById("cD");
clickDiv.addEventListener("click", function(){
if (animationDiv.style.animation == "") {
animationDiv.style.animation = " anim .5s forwards";
//animationDiv.style.animation = " anim running .1s infinite";
}else{
animationDiv.style.animation = ""; // assuming you want to toggle
}
});
#aD{ background-color:green;
height:30px;
margin:2px 0 5px 2px;}
#cD{background-color:blue;}
@keyframes anim{
0%{ background-color:green;}
100%{ background-color:red;}
}
#aD:hover{animation: anim 1s infinite;
cursor:pointer;}
<div id="aD">animated div</div>
<div id="cD">click div</div>
change mented line for different anim
本文标签: cssChanging webkitanimationplaystate with javascriptStack Overflow
版权声明:本文标题:css - Changing -webkit-animation-play-state with javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745661638a2161924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论