如何使用 jQuery 原地旋转图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11216769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:20:50  来源:igfitidea点击:

How To Rotate Image In Place With jQuery?

jqueryimagerotation

提问by gfy

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

});

});

回答by arttronics

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

我提供了一个 jsFiddle,它会在每次单击鼠标后导致 div 旋转

Essentially, this is from Example 5of the jqueryrotate.jsplugin.

从本质上讲,这是来自实施例5jqueryrotate.js插件。

Reference: jsFiddle

参考:jsFiddle

回答by Max Girkens

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

有一个 jQuery 补丁,它使您可以执行以下操作: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:

或者这个插件:http: //code.google.com/p/jqueryrotate/允许以下内容:

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

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

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

回答by Trufa

Here is a quick example using a jquery plugin called jqueryrotate

这是一个使用名为jqueryrotate的 jquery 插件的快速示例

See the jsfiddle here.

请参阅此处的 jsfiddle。