js代码
<script type="text/javascript" src="js/easing.js"></script> <script> var u = 100; var n = 1; var timer; //定义滚动的定时器 var result = 18912345678; //指定中奖结果,可以抽取指定数组中的某一个 var isBegin = false; //标识能否开始抽奖 $(".num").css('backgroundPositionY',200);//开始13888888888 $(".num").eq(0).css('backgroundPositionY',-100) $(".num").eq(1).css('backgroundPositionY',-300) //执行数字滚动 function run(){ n++; $(".num").each(function(index){ var _num = $(this); _num.animate({ backgroundPositionY: ((u+1)*n*(index+1)) },100); }); timer = window.setTimeout(run,100); isBegin = true ; } $(function(){ //开始抽奖 $('.start').click(function(){ if(isBegin){ return false; }else{ run(); } }); //停止抽奖 $('.stop').click(function(){ var num_arr = (result+'').split(''); $(".num").each(function(index){ var _num = $(this); setTimeout(function(){ _num.animate({ backgroundPositionY: (u*60) - (u*num_arr[index]) },{ duration: 500, easing: "easeInOutCirc", complete: function(){ if(index == 10){ isBegin = false; } } }); },100); }); window.clearTimeout(timer); isBegin = false ; }); }); </script>