从“开始”屏幕恢复动画 CSS3
resume animation css3 from start
>我试图制作一个停止 css3 动画并重新启动它的按钮我试过了这个功能 object.style.animationPlayState="paused";
但是我想从一开始就停止并重新运行它以不从最后一个地方恢复它的问题。
此外,我试图在停止也从最后一个位置开始之前操纵object.style.left
值。
我的最后一次尝试是将计数设置为 0,但到目前为止没有运气
关于这个问题有什么想法吗?
代码
<html>
<head>
<title>Move 3 pic's</title>
</head>
<style>
#div1{position: relative; top:100px;}
#div2{position: relative ; top:100px;left:290px;}
#div3{position: relative ; top:250px; left:50px;}
#divmain
{
width: 400px; height:300px; border: 10px solid navy; margin: 5px;
}
.animate1
{
animation: movingdiv1 5s infinite alternate;
animation-timing-function:linear;
}
.animate2
{
animation: movingdiv2 5s infinite alternate;
animation-timing-function:linear;
}
.animate3
{
animation: movingdiv3 5s infinite alternate;
animation-timing-function:linear;
}
@-moz-keyframes movingdiv1
{
from {left: 0px;}
to {left: 300px;}
}
@-moz-keyframes movingdiv2
{
from {left: 300px;}
to {left: 0px;}
}
@-moz-keyframes movingdiv3
{
from {top: 240px;}
to {top: 0px;}
}
</style>
<script>
var x=0;
function start()
{
document.getElementById("div1").style.animationIterationCount="infinite";
document.getElementById("div2").style.animationIterationCount="infinite";
document.getElementById("div3").style.animationIterationCount="infinite";
if(x==1)
{
document.getElementById("start").value="Stop";
document.getElementById("div1").style.animationPlayState="running";
document.getElementById("div2").style.animationPlayState="running";
document.getElementById("div3").style.animationPlayState="running";
x=0;
}
else
{
document.getElementById("start").value="Start";
document.getElementById("div1").style.animationPlayState="paused";
document.getElementById("div2").style.animationPlayState="paused";
document.getElementById("div3").style.animationPlayState="paused";
x=1;
}
}
function reset()
{
/*what i tried here*/
document.getElementById("div1").style.animationPlayState="paused";
document.getElementById("div2").style.animationPlayState="paused";
document.getElementById("div3").style.animationPlayState="paused";
document.getElementById("div1").style.left="0px";
document.getElementById("div2").style.left="297px";
document.getElementById("div3").style.top="250px";
document.getElementById("div1").style.animationIterationCount="0";
document.getElementById("div2").style.animationIterationCount="0";
document.getElementById("div3").style.animationIterationCount="0";
}
</script>
<body>
<div id=divmain>
<span class="animate1" id=div1>
<img src="icon1.gif" id="icon1" width="50" height="50"/></span>
<span class="animate2" id=div2>
<img src="icon2.gif" id="icon2" width="50" height="50"/></span>
<span class="animate3" id=div3><img src="top.jpg" id="icon3" width="50" height="50"/></span>
</div>
<input id=start type=button onClick=start() value='Stop'>
<input id=reset type=button onClick=reset() value='Reset'>
</body>
如果要
从头开始重新运行动画,请删除动画属性中的"备用"。
.animate1
{
animation: movingdiv1 5s infinite;
animation-timing-function:linear;
}
.animate2
{
animation: movingdiv2 5s infinite;
animation-timing-function:linear;
}
.animate3
{
animation: movingdiv3 5s infinite;
animation-timing-function:linear;
}
编辑:
也许我之前没有理解你的问题。您希望在单击按钮时停止并从头开始重新运行它。为此,我修改了启动函数()。每当按下停止按钮时,动画类都会从移动的div 中删除。按下开始按钮时,将添加动画类。
function start()
{
document.getElementById("div1").style.animationIterationCount="infinite";
document.getElementById("div2").style.animationIterationCount="infinite";
document.getElementById("div3").style.animationIterationCount="infinite";
if(x==1)
{
document.getElementById("start").value="Stop";
document.getElementById("div1").className = "animate1";
document.getElementById("div2").className = "animate2";
document.getElementById("div3").className = "animate3";
x=0;
}
else
{
document.getElementById("start").value="Start";
document.getElementById("div1").className = "";
document.getElementById("div2").className = "";
document.getElementById("div3").className = "";
x=1;
}
}
相关文章:
- 如何设置html元素填充的动画
- 我如何暂停和恢复这个动画,它可以用纯CSS完成吗
- CSS 动画将恢复为原始状态
- JQuery动画完整功能:如何恢复我的"老这个”;
- 拉斐尔.js动画恢复()在片场失败
- 开始按钮用于启用和恢复动画,而无需在双击时再次重复该功能(javascript)
- 停止无限CSS3动画并平滑恢复到初始状态
- 向上滚动时,基于滚动位置的 javascript 动画不会恢复到其原始状态
- 元素在 JQuery 动画后恢复为原始大小
- 从“开始”屏幕恢复动画 CSS3
- 在窗口大小调整事件开始时暂停 Greensock 动画,在调整大小事件结束时恢复动画
- 缩短jQuery动画功能,并在键盘上恢复到“开始”
- Jquery 2.0 -在点击时恢复动画
- CSS Animation -play-state问题:动画恢复时跳转回初始帧
- 如何防止引导转盘在单击右/左控件后恢复幻灯片动画
- 暂停一个动画2秒,然后在jQuery中自动恢复它(不在鼠标悬停或鼠标移出中)
- Jquery 动画选项卡 - 在鼠标退出时恢复
- 暂停和恢复JQuery.动画对象
- jQuery暂停/恢复动画
- 如何在点击时将动画恢复到原来的大小和位置