Results 1 to 2 of 2

Thread: Rotate An Image Once

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default Rotate An Image Once

    Using JQuery 1.11 why does the img rotate and the input disappear:
    Code:
    $(function() {
        var $elie = $("img"), degree = 0, timer;
      
        function rotate() {
            
            $elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
            $elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});                      
            timer = setTimeout(function() {
                ++degree; rotate();
                if(degree%360==0){clearTimeout(timer);}
            },5);
        }
        
        $("input").toggle(function() {
            clearTimeout(timer);
        }, function() {
            rotate();
        });
    });
    HTML Code:
    <input type="button" value=" Toggle Spin " />
    <br/><br/><br/><br/>
    <img src="http://i.imgur.com/ABktns.jpg" />
    Last edited by Deadweight; 08-26-2014 at 11:02 PM.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Resolved:
    Code:
    $(function() {
       var $elie = $("img"), degree = 1, timer;
      
        function rotate() {
            
            $elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
            $elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});                      
            timer = setTimeout(function() {
                ++degree; rotate();
                if(degree%360==0){clearTimeout(timer);}
            },5);
        }
        
        $("input").click(function() {
            
            rotate(); 
        });
    });
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

Similar Threads

  1. How to rotate the image Like this using css?
    By soumya in forum JavaScript
    Replies: 5
    Last Post: 03-22-2010, 09:36 AM
  2. rotate image background
    By asoekaya in forum CSS
    Replies: 1
    Last Post: 08-03-2008, 02:03 AM
  3. rotate image in javascript
    By jeanmichelo in forum JavaScript
    Replies: 4
    Last Post: 05-16-2008, 02:44 AM
  4. Rotate an Image 90° or 180° ?
    By Traveler in forum Looking for such a script or service
    Replies: 24
    Last Post: 01-15-2008, 03:44 AM
  5. PHP Image Rotate
    By Medyman in forum Looking for such a script or service
    Replies: 0
    Last Post: 12-12-2007, 06:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •