How To Rotate Image In Place With jQuery?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 04:38:13

问题


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})
    }
 } 

});


回答1:


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




回答2:


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/)




回答3:


Here is a quick example using a jquery plugin called jqueryrotate

See the jsfiddle here.



来源:https://stackoverflow.com/questions/11216769/how-to-rotate-image-in-place-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!