jQuery-如何“重置" .css()旋转的图标? [英] jQuery - how to "reset" a .css() rotated icon?
本文介绍了jQuery-如何“重置" .css()旋转的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图标,单击后会旋转.
我想重置"它(不刷新页面),因此它会在每次点击时旋转.
$('#icon').click(function(){
$(this).css('transform','rotate(360deg)');
});
这里是示例: http://jsfiddle.net/tDvD9/1/ >
谢谢!
解决方案
这是一种简单的方法:
var r = 0;
$('#icon').click(function(){
$(this).css('transform','rotate(' + (r += 360) + 'deg)');
});
这样,您的转换"属性将在每次点击时发生变化(直到有人点击1亿次左右).
I have an icon, which is rotated on click.
I'd like to "reset" it (without a page refresh), so it would rotate on every click.
$('#icon').click(function(){
$(this).css('transform','rotate(360deg)');
});
Here is the example: http://jsfiddle.net/tDvD9/1/
Thanks!
解决方案
Here's one simple way:
var r = 0;
$('#icon').click(function(){
$(this).css('transform','rotate(' + (r += 360) + 'deg)');
});
That way your "transform" property will change on each click (until somebody clicks 100 million times or so).
这篇关于jQuery-如何“重置" .css()旋转的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文