怎么创网站赚钱手机百度云网页版登录
jquery轮循
只是《命运之轮》的快速演示。 带有胜利/失败的随机旋转动画命运轮。
注意:为了更好地测试下面的演示,请在jsfiddle中将其打开。
要求:
- jQuery的
- Transit.js
示范 代码
代码– jQuery
window.WHEELOFFORTUNE = {cache: {},init: function () {console.log('controller init...');var _this = this;this.cache.wheel = $('.wheel');this.cache.wheelMarker = $('.marker');this.cache.wheelSpinBtn = $('.wheel'); //im using the wheel as the spin button but simply change this to a button if you want.//mapping is backwards as wheel spins clockwise //1=winthis.cache.wheelMapping = [400, 120, 80, 750, 150, 300, 60, 175, 500, 125, 75, 1000, 120, 200, 90, 600, 100, 250].reverse();this.cache.wheelSpinBtn.on('click', function (e) {e.preventDefault();if (!$(this).hasClass('disabled')) _this.spin();});//reset wheelthis.resetSpin();//setup prize eventsthis.prizeEvents();},spin: function () {console.log('spinning wheel');var _this = this;// reset wheelthis.resetSpin();//disable spin button while in progressthis.cache.wheelSpinBtn.addClass('disabled');/*Wheel has 10 sections.Each section is 360/10 = 36deg.*/var deg = 1500 + Math.round(Math.random() * 1500),duration = 6000; //optimal 6 secs_this.cache.wheelPos = deg;//transition queuing//ff bug with easeOutBackthis.cache.wheel.transition({rotate: '0deg'}, 0).transition({rotate: deg + 'deg'}, duration, 'easeOutCubic');//move marker_this.cache.wheelMarker.transition({rotate: '-20deg'}, 0, 'snap');//just before wheel finishsetTimeout(function () {//reset marker_this.cache.wheelMarker.transition({rotate: '0deg'}, 300, 'easeOutQuad');}, duration - 500);//wheel finishsetTimeout(function () {// did it win??!?!?!var spin = _this.cache.wheelPos,degrees = spin % 360,percent = (degrees / 360) * 100,segment = Math.ceil((percent / 6)), //divided by number of segmentswin = _this.cache.wheelMapping[segment - 1]; //zero based arrayconsole.log('spin = ' + spin);console.log('degrees = ' + degrees);console.log('percent = ' + percent);console.log('segment = ' + segment);console.log('win = ' + win);//display dialog with slight delay to realise win or not.setTimeout(function () {alert('you won '+win+'!');}, 700);//re-enable wheel spin_this.cache.wheelSpinBtn.removeClass('disabled');}, duration);},resetSpin: function () {this.cache.wheel.transition({rotate: '0deg'}, 0);this.cache.wheelPos = 0;}}window.WHEELOFFORTUNE.init();
代码– CSS
.wheel-wrap {position: relative;width: 550px;height: 550px;overflow: hidden;margin: 0 auto;z-index: 1;
}
.marker {top: 10px;left: 250px;z-index: 2;position: absolute;
}
.wheel {top: 90px;left: 75px;width: 550px;z-index: 1;
}
代码– HTML
翻译自: https://www.sitepoint.com/jquery-wheel-fortune-demo/
jquery轮循