jquery在单击时多次设置旋转div的动画

jquery在单击时多次设置旋转div的动画,jquery,rotation,jquery-animate,Jquery,Rotation,Jquery Animate,我想旋转这个div点击使用动画(不旋转,没有插件),并设置它可以旋转多少次。这是密码 $('#foo')。设置动画({borderSpacing:-90}{ 步骤:函数(现在,fx){ $(this).css('-webkit transform',rotate('+now+'deg'); $(this).css('-moz transform',rotate('+now+'deg'); $(this.css('transform','rotate('now+'deg'); }, 持续时间:'

我想旋转这个div点击使用动画(不旋转,没有插件),并设置它可以旋转多少次。这是密码

$('#foo')。设置动画({borderSpacing:-90}{
步骤:函数(现在,fx){
$(this).css('-webkit transform',rotate('+now+'deg');
$(this).css('-moz transform',rotate('+now+'deg');
$(this.css('transform','rotate('now+'deg');
},
持续时间:'慢'
}“线性”)
正文{
字体系列:无衬线;
}
#福{
宽度:100px;
高度:100px;
位置:绝对位置;
顶部:100px;
左:100px;
边界间距:0;
背景色:红色;
}

正文

请参见
这是解决方案snipet。希望你喜欢

$('#act')。在('click',function()上{
$(this).animate({borderSpacing:-90}{
步骤:函数(现在,fx){
$(this).css('-webkit transform',rotate('+now+'deg');
$(this).css('-moz transform',rotate('+now+'deg');
$(this.css('transform','rotate('now+'deg');
},
持续时间:'慢'
}“线性”);
});
正文{
字体系列:无衬线;
}
#表演{
宽度:100px;
高度:100px;
位置:绝对位置;
顶部:100px;
左:100px;
边界间距:0;
背景色:红色;
}

正文

请参见
这是解决方案snipet。希望你喜欢

$('#act')。在('click',function()上{
$(this).animate({borderSpacing:-90}{
步骤:函数(现在,fx){
$(this).css('-webkit transform',rotate('+now+'deg');
$(this).css('-moz transform',rotate('+now+'deg');
$(this.css('transform','rotate('now+'deg');
},
持续时间:'慢'
}“线性”);
});
正文{
字体系列:无衬线;
}
#表演{
宽度:100px;
高度:100px;
位置:绝对位置;
顶部:100px;
左:100px;
边界间距:0;
背景色:红色;
}

正文

请参见第一次:您需要使用
deg
而不是
borderspace
,以避免每次重置

2nd:我创建了两个函数,一个用于旋转,另一个用于重置旋转

3rd:添加
data
属性以捕捉
角度及其变化

下面的代码/注释将解释这些步骤:请仔细阅读代码注释

$(文档).ready(函数(){
$('#foo')。在('click',function(){//元素单击事件
var rotate_deg=parseInt($(this).data('rotate');//在这种情况下,获取数据rotate属性将返回-90,如果愿意,可以在html上更改它
var next_rotation_angle=rotate_deg-90;//对于新的旋转角度..在这种情况下,我使用rotate_deg*2根据需要更改它
var Times=3;//有多少个旋转可用
如果(旋转90度>=-次){
RotateIt($(this),rotate_deg);//运行函数旋转元素
$(this).data('rotate',next_rotation_angle);//将新角度附加到数据旋转属性
}否则{alert('不能再单击')}
});
$(“#重置_旋转”)。在('click',function(){//重置按钮单击事件
ResetRotate($('#foo'));//将元素旋转重置为0
$('#foo')。数据('旋转','-90');
});
});
//用于旋转的函数。。使用此代码通过使用RotateIt(元素,旋转度)旋转所需的任何元素;
功能旋转(el,度){
$(el).stop().animate({deg:deg}{
步骤:函数(现在,fx){
$(this).css('-webkit transform',rotate('+now+'deg');
$(this).css('-moz transform',rotate('+now+'deg');
$(this.css('transform','rotate('now+'deg');
},
持续时间:'慢'
}“线性”);
}
//用于重置旋转的功能。。虽然这里的deg为0,但不需要将deg设置为参数
功能复位旋转(el){
$(el).stop().animate({deg:0}{
步骤:函数(现在,fx){
$(this).css('-webkit transform',rotate('+now+'deg');
$(this).css('-moz transform',rotate('+now+'deg');
$(this.css('transform','rotate('now+'deg');
},
持续时间:'慢'
}“线性”);
}
正文{
字体系列:无衬线;
}
#福{
宽度:100px;
高度:100px;
位置:绝对位置;
顶部:100px;
左:100px;
边界间距:0;
背景色:红色;
}

正文
看

重置旋转
1st:您需要使用
deg
而不是
边框间距
,以避免每次重置

2nd:我创建了两个函数,一个用于旋转,另一个用于重置旋转

3rd:添加
data
属性以捕捉
角度及其变化

下面的代码/注释将解释这些步骤:请仔细阅读代码注释

$(文档).ready(函数(){
$('#foo')。在('click',function(){//元素单击事件
var rotate_deg=parseInt($(this).data('rotate');//在这种情况下,获取数据rotate属性将返回-90,如果愿意,可以在html上更改它
var next_rotation_angle=rotate_deg-90;//对于新的旋转角度..在这种情况下,我使用rotate_deg*2根据需要更改它
var Times=3;//有多少个旋转可用
如果(旋转90度>=-次){
RotateIt($(this),rotate_deg);//运行函数旋转元素
$(this).data('rotate',next_rotation_angle);//将新角度附加到数据旋转属性
}否则{alert('不能再单击')}
});
$(“#重置_旋转”)。在('click',function(){//重置按钮单击事件
ResetRotate($('#foo'));//将元素旋转重置为0
$('#foo')。数据('旋转','-90');
});
});
//用于旋转的函数。。使用此代码通过使用RotateIt(元素,旋转度)旋转所需的任何元素;
功能旋转(el,度){
$(el).stop().animate({deg:deg}{
步骤:函数(现在,fx){
$(this).css('-webkit-t