PHP & JavaScript Room :: 設置サンプル

実行結果

設置サンプル

animation-play-state

アニメーションの実行・一時停止を取得・設定します。

animation-play-state:   

実行状態: 

Sample

設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
      <title>animation-play-state</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
      <script type="text/javascript" src="./js/jquery.vendorprefix.js"></script>
      <script type="text/javascript">
         $(function(){
            var prefix=$.fn.VendorPrefix();
            var timer = setInterval(function(){
               getPlayState(prefix);
            },100);
            $("#running").click(function(){
               var $obj=$("#sample p");
               $obj.css("animation-play-state",this.id);
               $obj.css(prefix+"animation-play-state",this.id);
            });
            $("#paused").click(function(){
               var $obj=$("#sample p");
               $obj.css("animation-play-state",this.id);
               $obj.css(prefix+"animation-play-state",this.id);
            });
          });
          function getPlayState(prefix){
             var _state="";
             if($("#sample p").css("animation-play-state")){
                _state=$("#sample p").css("animation-play-state");
             }
             if($("#sample p").css(prefix+"animation-play-state")){
                _state=$("#sample p").css(prefix+"animation-play-state");
             }
             $("#state").html(_state);
          }
      </script>
      <style type="text/css">
         #sample {
            width:300px; height:300px;
            background:#eee;
         }
         #sample p {
            margin:0; padding:0;
            width:100px; height:100px;
            background:#ccc;
            position:relative;
            line-height:100px;
            text-align:center;
            font-weight:bold;
            
            animation:myani 5s ease 1s infinite alternate; /* CSS3 */
            -webkit-animation:myani 5s ease 1s infinite alternate; /* Chrome, Safari */
            -moz-animation:myani 5s ease 1s infinite alternate; /* Firefox */
            -ms-animation:myani 5s ease 1s infinite alternate; /* IE */
            -o-animation:myani 5s ease 1s infinite alternate; /* Opera */
         }
         @keyframes myani {
             from {left:0px;}
             to {left:200px;}
         }
         @-webkit-keyframes myani {
             from {left:0px;}
             to {left:200px;}
         }
         @-moz-keyframes myani {
             from {left:0px;}
             to {left:200px;}
         }
         @-ms-keyframes myani {
             from {left:0px;}
             to {left:200px;}
         }
         @-o-keyframes myani {
             from {left:0px;}
             to {left:200px;}
         }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>設置サンプル</h1>
         <h2>animation-play-state</h2>
         <p>アニメーションの実行・一時停止を取得・設定します。</p>
<!-- CODE -->
         <p>
            animation-play-state: 
            <input type="button" id="running" value="再開" /> 
            <input type="button" id="paused" value="停止" />
         </p>
         <p>
            実行状態: <span id="state"></span>
         </p>
         <div id="sample">
            <p>Sample</p>
         </div>
<!-- CODE / -->
      </div>
   </body>
</html>