DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS3基礎
11.9 動畫播放狀態 animation-play-state
編輯:CSS3基礎     

一、animation-play-state 屬性

顧名思義,這個屬性控制動畫是正在播放,還是暫停。

語法:

animation-play-state:取值;

animation-play-state 屬性取值
屬性值說明
running播放動畫(預設值)
paused暫停動畫

舉例:

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>CSS3 animation-play-state屬性</title>
<style type="text/css">
@-webkit-keyframes mytranslate {
  0%{}
  50%{-webkit-transform:translateX(200px);}
  100%{}
}
#div1 {
  width:40px;
  height:40px;
  border-radius:20px;
  background-color:red;
  -webkit-animation-name:mytranslate;
  -webkit-animation-timing-function:linear;
  -webkit-animation-duration:3s;
  -webkit-animation-iteration-count:infinite;
}
#container {
  display:inline-block;
  width:240px;
  border:1px solid silver;
}
</style>
<script src="../App_js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
  $("#btn_pause").click(function () {
    $("#div1").css("-webkit-animation-play-state", "paused");
  });
  $("#btn_run").click(function () {
    $("#div1").css("-webkit-animation-play-state", "running");
  });
})
</script>
</head>
<body>
<div id="container">
<div id="div1"></div>
</div>
<div id="control_btn">
<input id="btn_pause" type="button" value="暫停"/>
<input id="btn_run" type="button" value="播放"/>
</div>
</body>
</html>

分析:

這裡用 jQuery 綁定兩個按鈕:按「暫停」時把 animation-play-state 設為 paused,按「播放」時改回 running。效果就跟影片播放器的播放與暫停鍵一樣——動畫停在當下的進度,接著播放時從原位繼續,而不是從頭開始。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved