繁体   English   中英

使用jQuery单击多次旋转图像

[英]rotate an image multiple times on click with jquery

我正在尝试使用jquery旋转图像,该图像将在多次单击鼠标时旋转。 使用jquery-rotate插件,以下代码仅旋转图像一次(在firefox中转换为画布),并且在再次单击时不再旋转。

$(".drag-and-rotatable img").click(function() {
    $(this).rotate(45);
});

我愿意使用其他JavaScript库。

当您说rotate(45) ,您是将图像旋转45度吗? (请确保它不是弧度,我不使用插件)是从原始旋转开始的,因此,如果要继续旋转,则必须继续增加或减少度数:

$(function() {                                    // doc ready
    var rotation = 0;                             // variable to do rotation with
    $(".drag-and-rotatable img").click(function() {
        rotation = (rotation + 45) % 360; // the mod 360 probably isn't needed
        $(this).rotate(rotation);
    });
});

暂无
暂无

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

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