简体   繁体   English

如何在单击鼠标时重复旋转变换?

[英]How to repeat a rotate transformation on mouse click?

Don`t blame me for this question, I´m really new to jquery! 不要因为这个问题而责怪我,我真的是jquery新手!

I have an image (hamburger icon for a nav-menu) and would like to repeat the rotation when I click the image. 我有一张图片(导航菜单的汉堡图标),当我单击图片时想重复旋转。

$(document).ready(function(){
$('#nav-toggle').click(function(){
    $(this).css({
        "-webkit-transform": "rotate(90deg)",
        "-moz-transform": "rotate(90deg)",
        "transform": "rotate(90deg)"
    });
});

Take your anonomous function and break it out. 采取您的匿名功能并将其突破。 That way, you can call it all you want. 这样,您就可以随心所欲。

$(document).ready(function(){
$('#nav-toggle').click(function(){
    transform($(this));
});

$('<item>').onMouseClick(function(){
    transform($(this));
});

function transform(var nav){
    nav.css({
        "-webkit-transform": "rotate(90deg)",
        "-moz-transform": "rotate(90deg)",
        "transform": "rotate(90deg)"
    }

if you want the "#nav-toogle" to rotate "90deg" for every click you can do 如果您希望“#nav-toogle”每次点击都旋转“ 90deg”,则可以执行

$('#nav-toggle').click(function(){
    if($(this).data("deg")){
         $(this).data("deg",$(this).data("deg")+90);
    }
    else{
         $(this).data("deg",90);
    }
    $(this).css({
        "-webkit-transform": "rotate("+$(this).data("deg")+"deg)",
        "-moz-transform": "rotate("+$(this).data("deg")+"deg)",
        "transform": "rotate("+$(this).data("deg")+"deg)"
    });
});    

http://jsfiddle.net/QrKrX/ http://jsfiddle.net/QrKrX/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM