幸运转盘js

阅读更多
function luckWheel(wheelDiv,data) {
	var round = 5,
		divisor = data.length,
		partDegree = 360/divisor,
		offset = partDegree/2,
		random = Math.floor(Math.random() * data.length),
		target = partDegree*random;
	
	wheelDiv.stopRotate();
	wheelDiv.rotate({
		angle: 0,
		duration: round*1000,
		animateTo: offset+ target + 360*round, 
		callback: function() {
			isRunning = false;
			alert(data[random]);
		}
	});
}

// 调用方式:
var data = [
	'双季丰0.1%加息红包', 
	'双季丰满减红包10元', 
	'1元现金红包', 
	'财金币20枚', 
	'20元现金红包', 
	'双季丰0.5%加息红包', 
	'双季丰满减红包50元', 
	'5元现金红包'];
luckWheel($('#luck-wheel'),data);

你可能感兴趣的:(幸运转盘js)