需求如下:
让元素随中心转动当鼠标放上去则停止,鼠标移开,在停止位置继续旋转。
核心代码:
<script type="text/javascript">
$(function(){
var currentAngle = 0;
var rotation = null;
start();
$('#lotteryBtn').rotate({
bind : {
mouseover : function(){
stop();
}, mouseout : function(){
start();
}
}
});
function start(){
console.log("start"+currentAngle);
var angle = parseInt(currentAngle);
rotation = setInterval(function(){
angle +=3;
$('#lotteryBtn').rotate(angle);
}, 50);
}
function stop(){
currentAngle = $('#lotteryBtn').getRotateAngle();
clearInterval(rotation);
rotation = null;
}
});
</script>
下载地址: http://download.csdn.net/detail/huaishuming/8118449