我正在使用这个 jQuery 插件:http://code.google.com/p/jqueryrotate/wiki/Documentation
我已经让插件正常工作了,但是我想要做的是单击一个按钮来旋转图像,每次单击按钮时,它都会连续旋转 +/- 90 度,而不仅仅是旋转到一定程度。我不太确定如何使用这个插件来完成此任务。
理想情况下,下面的代码可以实现我想要的功能,尽管事实并非如此。
$("body").on("click", ".theater-wrapper img", function(){
$(".theater-wrapper .current").rotate(+90);
});
最佳答案
类似这样的吗?
$("body").on("click", ".theater-wrapper img", function(){
$(".theater-wrapper .current").rotate(getNextAngle());
});
nextAngle = 0;
function getNextAngle() {
nextAngle += 90;
if(nextAngle >= 360) {
nextAngle = 0;
}
return nextAngle;
}
可能没什么大不了的,但为了避免获得巨大的数字,您可以在需要时将该值重置为 0。
关于jQuery 旋转图像(使用旋转插件)每次单击旋转 +/-90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12906855/