HTML DOM樣式animationPlayState屬性用於指定動畫是運行還是暫停。
用法:
animation-play-state:running|paused|initial|inherit;
屬性值:
- running:此值用於運行/播放動畫。
- paused:此值用於暫停動畫。
- initial:此值將animation-play-state屬性設置為父元素的值。
- inherit:此值用於將.animation-play-state屬性設置為default(運行)。
例:animation-play-state:正在運行
<!DOCTYPE html>
<html>
<head>
<title>
HTML | DOM Style animationPlayState Property
</title>
<style>
div {
height:100px;
width:150px;
font-size:100px;
-webkit-animation:movement 3s infinite;
-webkit-animation-play-state:paused;
animation:movement 3s infinite;
color:darkgreen;
position:relative;
<!-- property value "running" -->
animation-play-state:running;
}
@-webkit-keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
@keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
</style>
</head>
<body>
<br>
<div id="block">Geeks For Geeks</div>
</body>
</html>
輸出:
例:animation-play-state:已暫停
<!DOCTYPE html>
<html>
<head>
<title>
HTML | DOM Style animationPlayState Property
</title>
<style>
div {
height:100px;
width:150px;
font-size:100px;
-webkit-animation:movement 3s infinite;
-webkit-animation-play-state:paused;
animation:movement 3s infinite;
color:darkgreen;
position:relative;
<!-- property value "paused" -->
animation-play-state:paused;
}
@-webkit-keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
@keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
</style>
</head>
<body>
<button onclick="Play()">
Click to make the object move
</button>
<script>
function Play() {
document.getElementById("block"
).style.WebkitAnimationPlayState = "running";
document.getElementById("block"
).style.animationPlayState = "running";
}
</script>
<br>
<div id="block">Geeks For Geeks</div>
</body>
</html>
輸出:
例:animation-play-state:繼承
<!DOCTYPE html>
<html>
<head>
<title>
HTML | DOM Style animationPlayState Property
</title>
<style>
div {
height:50px;
width:150px;
font-size:100px;
-webkit-animation:movement 3s infinite;
-webkit-animation-play-state:paused;
animation:movement 3s infinite;
color:darkgreen;
position:relative;
animation-play-state:running;
}
h4 {
width:150px;
-webkit-animation:movement 3s infinite;
-webkit-animation-play-state:paused;
animation:movement 3s infinite;
color:darkgreen;
position:relative;
<!-- property value "inherit" -->
animation-play-state:inherit;
}
@-webkit-keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
@keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
</style>
</head>
<body>
<br>
<div id="block">
Gfg
<h4> I'm inherited</h4>
</div>
</body>
</html>
輸出:
例:animation-play-state:初始
<!DOCTYPE html>
<html>
<head>
<title>
HTML | DOM Style animationPlayState Property
</title>
<style>
div {
height:100px;
width:150px;
font-size:100px;
-webkit-animation:movement 3s infinite;
-webkit-animation-play-state:paused;
animation:movement 3s infinite;
color:darkgreen;
position:relative;
<!-- property value "initial" -->
animation-play-state:initial;
}
@-webkit-keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
@keyframes movement {
from {
left:50px;
}
to {
left:400px;
}
}
</style>
</head>
<body>
<br>
<div id="block">Geeks For Geeks</div>
</body>
</html>
輸出:
支持的瀏覽器:下麵列出了animation-play-state屬性支持的瀏覽器:
- Chrome:43.0(4.0 Webkit)
- 的Firefox:16.0
- Safari:4.0 Webkit
- 邊:10.0
- Opera:30.0(15.0 Webkit)
相關用法
- HTML Style right用法及代碼示例
- HTML Style top用法及代碼示例
- HTML Style textAlign用法及代碼示例
- HTML Style borderRight用法及代碼示例
- HTML Style borderLeft用法及代碼示例
- HTML Style wordSpacing用法及代碼示例
- HTML Style textDecorationLine用法及代碼示例
- HTML Style height用法及代碼示例
- HTML Style whiteSpace用法及代碼示例
- HTML Style opacity用法及代碼示例
- HTML Style columnRuleStyle用法及代碼示例
- HTML Style display用法及代碼示例
- HTML Style transformStyle用法及代碼示例
- HTML Style visibility用法及代碼示例
- HTML Style cssFloat用法及代碼示例
注:本文由純淨天空篩選整理自roshalmoraes大神的英文原創作品 HTML | DOM Style animationPlayState Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。