抽奖大转盘效果分享

html部分*此文章为转载内容*
这里写图片描述
css部分
*{
padding: 0;
margin: 0;
}
.wrapper{
position: relative;
width: 400px;
height: 400px;
margin: 100px auto;
}
.wrapper .box{
width: 100%;
height: 100%;
}
.wrapper .box img{
width: 100%;
}
.wrapper #button{
position: absolute;
top: 50%;
left: 50%;
margin-top: -65px;
margin-left: -65px;
width: 130px;
height: 130px;
border-radius: 50%;
}
.wrapper #button img{
position: absolute;
top: -23px;
width: 130px;
}
js实现效果
var pars = {
rotateNum: 8,
body: ‘.wrapper’,
clickCb: clickCbFun,
renderCb: renderCbFun
}

var lottery = new Lottery(pars);
function clickCbFun() {
var random = Math.floor(Math.random() * 360);
lottery.goRotate(random);
}
function renderCbFun(deg) {
var str = ”;
if(deg >= 0 && deg < 45) {
str = ‘二等奖’;
}else if(deg >= 45 && deg < 90 || deg >= 135 && deg < 180 || deg >= 225 && deg < 270 || deg >= 315 && deg < 360) {
str = ‘四等奖’;
}else if(deg >= 90 && deg < 135 || deg >= 270 && deg < 315) {
str = ‘三等奖’;
}else if(deg >= 180 && deg < 225) {
str = ‘一等奖’;
}
alert(‘恭喜你获得’+str);
}
jQuery实现
(function (win, ) {  
    var defaultPar = {  
        rotateNum: 5,  
        body: ‘body’,  
        clickCb: function () {},  
        renderCb: function () {}  
    }  
    win.Lottery = Lottery;  
    function Lottery(pars) {  
        this.pars =
) {      var defaultPar = {          rotateNum: 5,          body: ‘body’,          clickCb: function () {},          renderCb: function () {}      }      win.Lottery = Lottery;      function Lottery(pars) {          this.pars =
.extend(true, {}, defaultPar, pars);
this.isDoing = false;
this.init();
}
Lottery.prototype.init = function () {
var _this = this;
// this.rotateAll = this.pars.rotateNum * 360;
(this.pars.body).on(‘click’, ‘#button’, function () {  
            if(!_this.isDoing) {  
                _this.isDoing = true;  
                _this.pars.clickCb();  
            }  
        })
(this.pars.body).on(‘click’, ‘#button’, function () {              if(!_this.isDoing) {                  _this.isDoing = true;                  _this.pars.clickCb();              }          })
(this.pars.body).find(‘.box’).get(0).addEventListener(‘webkitTransitionEnd’, function () {
var deg = (this.pars.body).attr(datadeg);this.pars.renderCb(deg); ( t h i s . p a r s . b o d y ) . a t t r ( ‘ d a t a − d e g ′ ) ; t h i s . p a r s . r e n d e r C b ( d e g ) ; (_this.pars.body).find(‘.box’).css({
transform: ‘rotate(’ + deg + ‘deg)’,
transition: ‘none’
})
_this.isDoing = false;
})
}
Lottery.prototype.goRotate = function (deg) {
// var rotateEnd = this.rotateAll + deg;
var rotateEnd = this.pars.rotateNum * 360 + deg;
(this.pars.body).find(.box).css(transform:rotate(+rotateEnd+deg),transition:all5s) ( t h i s . p a r s . b o d y ) . f i n d ( ‘ . b o x ′ ) . c s s ( t r a n s f o r m : ‘ r o t a t e ( ′ + r o t a t e E n d + ‘ d e g ) ′ , t r a n s i t i o n : ‘ a l l 5 s ′ ) (this.pars.body).attr(‘data-deg’,deg);
}

})(window, $)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值