asimryu

timer - rotate - 1

Jun 10th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.99 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="ko">
  3.  <head>
  4.   <meta charset="UTF-8">
  5.   <title>rotate</title>
  6.   <style>
  7.             .imgs img {
  8.                 margin:10px;
  9.                 border-radius:50px;
  10.                 transform: rotate(30deg);
  11.             }
  12.         </style>
  13.  </head>
  14.  <body>
  15.         <div class="imgs">
  16.             <img id="img1" src="http://lorempixel.com/100/100/animals">
  17.             <img id="img2" src="http://lorempixel.com/100/100/city">
  18.             <img id="img3" src="http://lorempixel.com/100/100/food">
  19.         </div>
  20.     <script src="./js/jquery-1.11.1.min.js"></script>
  21.     <script>
  22.         $(".imgs img").css("transform","rotate(0deg)");
  23.         var d = 0;
  24.         var timer = null;
  25.         function r(obj)
  26.         {
  27.             d = d + 10;
  28.             if( d > 360 ) d = 0;
  29.             var eff = "rotate(" + d + "deg)";
  30.             $("#" + obj).css("transform",eff);
  31.         }
  32.         $(".imgs img").hover(
  33.             function(){
  34.                 var obj = $(this).attr("id");
  35.                 timer = setInterval(
  36.                     function(){
  37.                         r( obj );
  38.                     }, 10
  39.                 );
  40.             },
  41.             function(){
  42.                 clearInterval(timer);
  43.                 timer =  null;
  44.             }
  45.         );
  46.     </script>
  47.  </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment