Javascript 使用jQuery旋转,记住位置

Javascript 使用jQuery旋转,记住位置,javascript,jquery,html,css,rotation,Javascript,Jquery,Html,Css,Rotation,我正在旋转一个div,就像下面的代码一样。 问题是,当我再次单击元素时,我不知道如何使它从上一个位置继续。我该怎么做?(我能够以一种在IE中不起作用的方式完成) HTML: JS: 你可以使用 并使用js代码 var value = 0 $("#image").rotate({ bind: { click: function(){ value +=90; $(this).rotate({

我正在旋转一个div,就像下面的代码一样。 问题是,当我再次单击元素时,我不知道如何使它从上一个位置继续。我该怎么做?(我能够以一种在IE中不起作用的方式完成)

HTML:

JS:

你可以使用

并使用js代码

var value = 0
$("#image").rotate({ 
   bind: 
     { 
        click: function(){
            value +=90;
            $(this).rotate({ animateTo:value})
        }
    }    
});
工作小提琴是。。。
希望这对您有用。

对不起,Illaya,我没有找到您的答案,因为我没有使用外部jquery代码。 我将JS更改为:

$(document).ready(function () {


$('.square').click(function () {
       if ($(this).hasClass('folded')) {
            $(this).removeClass('folded');
            rotate($(this), 0, 700);
        } else {
            $(this).addClass('folded');
            rotate($(this), 180, 700);
        }
});

    function rotate(element, degrees, speed) {
        element.animate({
            borderSpacing: degrees
        }, {
            duration: speed,
            step: function (now, fx) {
                $(this).css('-webkit-transform', 'rotate(' + now + 'deg)');
                $(this).css('-moz-transform', 'rotate(' + now + 'deg)');
                $(this).css('transform', 'rotate(' + now + 'deg)');
            }
        });
    }
});

只需使用两个不同的类,并使用jQuery进行交换切换即可。您想要左侧图像旋转还是右侧图像旋转?这是什么意思?我不在乎,汉克斯。我希望不必包含一些外部jquery代码,但是哦,好吧。。。再次感谢
$('.square').click(function () {
    rotate($(this), -180, 1000);
});

function rotate(element, degrees, speed) {
    element.animate({
        borderSpacing: degrees
    }, {
        duration: speed,
        step: function (now, fx) {
            $(this).css('-webkit-transform', 'rotate(' + now + 'deg)');
            $(this).css('-moz-transform', 'rotate(' + now + 'deg)');
            $(this).css('transform', 'rotate(' + now + 'deg)');
        }
    });
}
var value = 0
$("#image").rotate({ 
   bind: 
     { 
        click: function(){
            value +=90;
            $(this).rotate({ animateTo:value})
        }
    }    
});
$(document).ready(function () {


$('.square').click(function () {
       if ($(this).hasClass('folded')) {
            $(this).removeClass('folded');
            rotate($(this), 0, 700);
        } else {
            $(this).addClass('folded');
            rotate($(this), 180, 700);
        }
});

    function rotate(element, degrees, speed) {
        element.animate({
            borderSpacing: degrees
        }, {
            duration: speed,
            step: function (now, fx) {
                $(this).css('-webkit-transform', 'rotate(' + now + 'deg)');
                $(this).css('-moz-transform', 'rotate(' + now + 'deg)');
                $(this).css('transform', 'rotate(' + now + 'deg)');
            }
        });
    }
});