js代码
<script src="js/jquery.min.js"></script> <script src="js/easing.js"></script> <script> //随机数(停的位置) function numRand() { // 图片 每个图片 6个选项 var arr = ["0", "1", "2", "3", "4", "5"] var res = ""; for (var i = 0; i < 3; i++) { var rnd = Math.floor(Math.random() * arr.length); res += arr[rnd]; arr.splice(rnd, 1) } return res } function Lottery() { var isBegin = false; var u = 150; if (isBegin) return false; isBegin = true; $(".tiger").css('backgroundPositionY', 0); //一等奖 052 二等奖230 三等奖413 // var result = "413"; var result = numRand(); console.log(result) var num_arr = (result + '').split(''); console.log(num_arr) $(".tiger").each(function (index) { var _num = $(this); setTimeout(function () { _num.animate({ backgroundPositionY: (u * 60) - (u * num_arr[index]) }, { duration: 6000 + index * 3000, easing: "easeInOutCirc", complete: function () { isBegin = false; if (index == 2) { // 抽奖结束 启动按钮 可再次抽奖 $(".play").attr("disabled", false) } } }); }, index * 300); }); } $('.play').click(function () { // 点击抽奖的时候 不可立刻再次点击 此时禁用按钮 $(this).attr("disabled", true); Lottery() }); </script>