How To Rotate Image In Place With jQuery?

2019-04-25 10:52发布

I am trying to make an image rotate in place with each click (the image is an old-fashioned TV knob). I cannot get it to work despite my best efforts.

The code is below:

    var value = 0
$("#img").rotate({ 
bind: 
{ 
    click: function(){
        value +=90;
        $(this).rotate({ animateTo:value})
    }
 } 

});

3条回答
太酷不给撩
2楼-- · 2019-04-25 11:18

Here is a quick example using a jquery plugin called jqueryrotate

See the jsfiddle here.

查看更多
我只想做你的唯一
3楼-- · 2019-04-25 11:33

There is a jQuery patch, which enables you to do something like this: http://www.zachstronaut.com/posts/2009/08/07/jquery-animate-css-rotate-scale.html

$('#img').click(function(){
  $(this).animate({rotate: '+=10deg'}, 0);
});

Or this plugin: http://code.google.com/p/jqueryrotate/ which allow stuff like:

$("#img").rotate({
    bind: {
        click: function() {
            $(this).rotate({
                animateTo: (parseInt($(this).getRotateAngle()) + 10),
                easing: $.easing.easeInOutExpo
            })
        }
    }
});​

( http://jsfiddle.net/mFY22/3/)

查看更多
Explosion°爆炸
4楼-- · 2019-04-25 11:41

I'm providing a jsFiddle that causes the div to rotate after every mouse click.

Essentially, this is from Example 5 of the jqueryrotate.js plugin.

Reference: jsFiddle

查看更多
登录 后发表回答