asimryu

timer - rotate - 2

Jun 10th, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.53 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.             }
  11.         </style>
  12.  </head>
  13.  <body>
  14.         <div class="imgs">
  15.             <img id="img1" src="http://lorempixel.com/100/100/animals">
  16.             <img id="img2" src="http://lorempixel.com/100/100/city">
  17.             <img id="img3" src="http://lorempixel.com/100/100/food">
  18.         </div>
  19.     <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  20.     <script>
  21.         var d = 0;
  22.         var timer = null;
  23.         var obj = null;
  24.         function r(obj)
  25.         {
  26.             d = d + 10;
  27.             if( d > 180 ) {
  28.                 d = 180;
  29.                 clearInterval(timer);
  30.                 timer = null;
  31.             }
  32.             var eff = "rotate(" + d + "deg)";
  33.             $("#" + obj).css("transform",eff);
  34.         }
  35.         function r2(obj)
  36.         {
  37.             d = d - 10;
  38.             if( d < 0 ) {
  39.                 d = 0;
  40.                 clearInterval(timer);
  41.                 timer = null;
  42.             }
  43.             var eff = "rotate(" + d + "deg)";
  44.             $("#" + obj).css("transform",eff);
  45.         }
  46.         $(".imgs img").hover(
  47.             function(){
  48.                 if ( timer != null ) {
  49.                     clearInterval(timer);
  50.                     timer = null;
  51.                     d = 0;
  52.                     if( obj != null) {
  53.                         $("#" + obj).css("transform","rotate(0deg)");
  54.                     }
  55.                 }
  56.                 obj = $(this).attr("id");
  57.                 timer = setInterval(
  58.                     function(){
  59.                         r( obj );
  60.                     }, 10
  61.                 );
  62.             },
  63.             function(){
  64.                 if ( timer != null ) {
  65.                     clearInterval(timer);
  66.                     timer = null;
  67.                 }
  68.                 obj = $(this).attr("id");
  69.                 timer = setInterval(
  70.                     function(){
  71.                         r2( obj );
  72.                     }, 10
  73.                 );
  74.             }
  75.         );
  76.     </script>
  77.  </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment