急急急 关于抽奖转盘活动的一个问题 求大神帮忙解决下

yY930610 2017-09-13 04:41:45
后台技术 java 前端h5页面

现在有个问题 点击抽奖的时候 后台的逻辑查询太慢 要10秒左右才能返回抽中的奖品,返回成功后,转盘才开始转,这样用户的体验不是非常好

现在想修改成让转盘自己先转着 然后等后台返回结果 在结束旋转 但会有一些前端问题 比如转盘转着转着 等结果出来了会突然加速一下 然后会转到抽中的奖品这里,不是缓慢停下来的 下面是我转盘点击时触发的点击事件


<script>
$.popCtrl();
var prize = {
init: function (_opt) {
var _this = this;
var _default = {
circleCount: 2,
index: 0,
interval: 60,
count: 12,
callback: null
};

_this._opt = $.extend(_default, _opt);
_this.maxCount = _this._opt.circleCount * _this._opt.count + _this._opt.index + 1;
//console.log(_this.maxCount);
_this.curIndex = -1;

_this.prizeDom = $("#prizeBox").find(".item");

_this.timeInterval();
},
timeInterval: function (func) {

var _this = this;

_this.timeCtrl = window.setTimeout(function () {
_this.curIndex += 1;

if (_this.curIndex < _this.maxCount) {
_this.run(_this.index());
if (_this.curIndex > _this.maxCount - _this._opt.count) {
_this._opt.interval += 30;
}
_this.timeInterval();
}

else {
window.clearTimeout(_this.timeCtrl);
if (_this._opt.callback) {
_this._opt.callback();
}
}
}, _this._opt.interval);
},
index: function () {
var _this = this;
return _this.curIndex % _this._opt.count;
},
run: function (index) {
var _this = this;
_this.prizeDom.eq(index).addClass("cur");
_this.prizeDom.not(_this.prizeDom.eq(index)).removeClass("cur");

}

}

$("#beginPrize").bind("click", function () {
if ($("#beginPrize").hasClass("disabled")) {
return;
}
var count = $('#count').text();
if (count == 0) {
$('#tip').html("亲,您的抽奖次数用完了");
$('#cmd09').addClass('show');
return;
}
$("#beginPrize").addClass("disabled");
prize.init({
index:99999,
})
$.ajax({
type:"post",
url:"../luckywheel2/lottery.do",
cache:false,
success: function (data){
try{
data = eval('(' + data + ')');
}catch(e){
}
if(data != undefined){
//抽奖成功
if(data.ret==0){
if (data.data.awardInfoId==7) {
prize.init({
index: data.data.number,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#cmd01').addClass('show');
$('#count').html(data.data.count);
$("#beginPrize").removeClass("disabled");
}
});
}else{
prize.init({
index: data.data.number,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#prizeName').html(data.data.awardInfoName);
$('#infoid').val(data.data.id);
$('#count').html(data.data.count);
$('#cmd02').addClass('show');
$("#beginPrize").removeClass("disabled");
}
});
}
}else if(data.ret== "003"){
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("亲,您的抽奖次数用完了");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}else{
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html(data.data);
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
}else{
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("网络异常,请稍后尝试");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
},
error:function(){
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("网络异常,请稍后尝试");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
})
});
...全文
196 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李德胜1995 2017-09-13
  • 打赏
  • 举报
回复

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧