bigwheel-miniapp icon indicating copy to clipboard operation
bigwheel-miniapp copied to clipboard

两步解决指针位置计算错误的问题

Open Shemmor opened this issue 3 years ago • 1 comments

1、index.js在调用抽奖停止函数时传入奖品数组的长度

// 模拟后台返回数据 setTimeout(function () { // 随机一个奖品 var prizeIndex = utils.getRandom(slicePrizes.length - 1); // console.log(prizeIndex) //奖品数量 var prizeCounts = slicePrizes.length; // console.log(prizeCounts) // 计算奖品角度 animation.stopTo(prizeIndex,prizeCounts); }, 3000);

2、改变Animation.js的stopTo方法

Animation.prototype.stopTo = function (prizeIndex,prizeCounts) { var wheel = this.circle; var angle = wheel.angle;

var offset = (360/prizeCounts)/2; //应该是 (360/转盘奖品数量)/2

this.minAngle = prizeIndex * angle + offset; this.maxAngle = prizeIndex * angle + angle; this.prize = wheel.slicePrizes[prizeIndex]; };

Shemmor avatar Oct 16 '21 07:10 Shemmor

1、index.js在调用抽奖停止函数时传入奖品数组的长度

// 模拟后台返回数据 setTimeout(function () { // 随机一个奖品 var prizeIndex = utils.getRandom(slicePrizes.length - 1); // console.log(prizeIndex) //奖品数量 var prizeCounts = slicePrizes.length; // console.log(prizeCounts) // 计算奖品角度 animation.stopTo(prizeIndex,prizeCounts); }, 3000);

2、改变Animation.js的stopTo方法

Animation.prototype.stopTo = function (prizeIndex,prizeCounts) { var wheel = this.circle; var angle = wheel.angle;

var offset = (360/prizeCounts)/2; //应该是 (360/转盘奖品数量)/2

this.minAngle = prizeIndex * angle + offset; this.maxAngle = prizeIndex * angle + angle; this.prize = wheel.slicePrizes[prizeIndex]; };

你这种方式就是把指针固定到了中间的位置也可以的, 欢迎 提交 pull request

qiaohhgz avatar Oct 18 '21 07:10 qiaohhgz