用jQuery實(shí)現(xiàn)抽獎(jiǎng)程序
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)抽獎(jiǎng)程序的具體代碼,供大家參考,具體內(nèi)容如下
1. 主要需求
- 實(shí)現(xiàn)一個(gè)抽獎(jiǎng)功能。
- 點(diǎn)擊開始按鈕后,開始按鈕禁用,停止按鈕取消禁用,小圖片實(shí)現(xiàn)快速切換顯示。
- 點(diǎn)擊停止按鈕后,停止按鈕禁用,開始按鈕取消禁用,小圖片停止切換,將小圖片在大圖片位置顯示。
- 小圖片實(shí)現(xiàn)快速切換顯示。
- 點(diǎn)擊停止按鈕后,淡入淡出選中圖。
2. 素材頁(yè)面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>抽獎(jiǎng)程序</title> <script type="text/javascript" src="../js/jquery-1.11.1.js"></script> <style type="text/css"> #small { border: 1px solid blueviolet; width: 75px; height: 75px; margin-bottom: 20px; } #smallPhoto { width: 75px; height: 75px; } #big { border: 2px solid orangered; width: 500px; height: 500px; position: absolute; left: 300px; top: 10px } #bigPhoto { width: 500px; height: 500px; } #btnStart { width: 100px; height: 100px; font-size: 22px; } #btnStop { width: 100px; height: 100px; font-size: 22px; } </style> </head> <body> <!-- 小像框 --> <div id="small"> <img id="smallPhoto" src="../img/man00.png"/> </div> <!-- 大像框 --> <div id="big"> <img id="bigPhoto" src="../img/begin.jpg" /> </div> <input id="btnStart" type="button" value="點(diǎn)擊開始"/> <input id="btnStop" type="button" value="點(diǎn)擊停止"/ disabled> <script type="text/javascript"> </script> </body> </html>
3. 代碼實(shí)現(xiàn)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>抽獎(jiǎng)程序</title> <script type="text/javascript" src="../js/jquery-1.11.3.js"></script> <style type="text/css"> #small { border: 1px solid blueviolet; width: 75px; height: 75px; margin-bottom: 20px; } #smallPhoto { width: 75px; height: 75px; } #big { border: 2px solid orangered; width: 500px; height: 500px; position: absolute; left: 300px; top: 10px } #bigPhoto { width: 500px; height: 500px; } #btnStart { width: 100px; height: 100px; font-size: 22px; } #btnStop { width: 100px; height: 100px; font-size: 22px; } </style> </head> <body> <!-- 小像框 --> <div id="small"> <img id="smallPhoto" src="../img/man00.jpg"/> </div> <!-- 大像框 --> <div id="big"> <img id="bigPhoto" src="../img/begin.jpg" /> </div> <input id="btnStart" type="button" value="開始" onclick="gameStart()"> <input id="btnStop" type="button" value="停止" disabled onclick="gameOver()"> <script type="text/javascript"> //初始化抽獎(jiǎng)的名單(圖片地址) let imgs = [ "../img/man00.jpg", "../img/man01.jpg", "../img/man02.jpg", "../img/man03.jpg", "../img/man04.jpg", "../img/man05.jpg", "../img/man06.jpg", ]; //定時(shí)器序號(hào) let counter = null; //點(diǎn)擊開始 function gameStart() { //開始按鈕禁用 $("#btnStart").prop("disabled",true); //停止按鈕可用 $("#btnStop").prop("disabled",false); //定義計(jì)數(shù)變量 let num = 0; //使用定時(shí)器實(shí)現(xiàn)小圖框快速切換圖片 counter = setInterval(function () { //通過(guò)取余,循環(huán)得到數(shù)組得到索引 let index = num%imgs.length; //修改小圖框中img的src即可 $("#smallPhoto").attr("src",imgs[index]); //計(jì)數(shù)變量自增 num++; },20); } //點(diǎn)擊結(jié)束 function gameOver() { //禁用結(jié)束按鈕 $("#btnStop").prop("disabled",true); //取消開始按鈕的禁用 $("#btnStart").prop("disabled",false); //停止小圖框的抽獎(jiǎng)(停止定時(shí)器) clearInterval(counter); //將計(jì)算變量重置為0 num = 0; //獲取小圖框圖片地址 let imgUrl = $("#smallPhoto").attr("src"); //將抽獎(jiǎng)結(jié)果顯示在大圖框中,并隱藏起來(lái) $("#bigPhoto").attr("src",imgUrl).hide(); //將圖片進(jìn)行淡出 $("#bigPhoto").fadeIn(2000); } </script> </body> </html>
示例素材:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery+PHP+Mysql實(shí)現(xiàn)抽獎(jiǎng)程序
- jQuery實(shí)現(xiàn)簡(jiǎn)單的抽獎(jiǎng)游戲
- 用jQuery旋轉(zhuǎn)插件jqueryrotate制作轉(zhuǎn)盤抽獎(jiǎng)
- jQuery自定義數(shù)值抽獎(jiǎng)活動(dòng)代碼
- 基于jQuery實(shí)現(xiàn)的雙11天貓拆紅包抽獎(jiǎng)效果
- jquery.rotate.js實(shí)現(xiàn)可選抽獎(jiǎng)次數(shù)和中獎(jiǎng)內(nèi)容的轉(zhuǎn)盤抽獎(jiǎng)代碼
- jquery 年會(huì)抽獎(jiǎng)程序
- jquery 抽獎(jiǎng)小程序?qū)崿F(xiàn)代碼
- jQuery實(shí)現(xiàn)轉(zhuǎn)動(dòng)隨機(jī)數(shù)抽獎(jiǎng)效果的方法
- jquery實(shí)現(xiàn)九宮格大轉(zhuǎn)盤抽獎(jiǎng)
相關(guān)文章
使用jQuery的load方法設(shè)計(jì)動(dòng)態(tài)加載及解決被加載頁(yè)面js失效問(wèn)題
這篇文章主要介紹了使用jQuery的load方法設(shè)計(jì)動(dòng)態(tài)加載及解決被加載頁(yè)面js失效問(wèn)題,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03jQuery彈出窗口打開鏈接的實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery彈出窗口打開鏈接的實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-12-12基于jQuery制作小圖標(biāo)上下滑動(dòng)特效
一個(gè)小圖標(biāo)特效,非常有趣的,下面給大家分享基于jquery制作的小圖標(biāo)上下滑動(dòng)特效,代碼簡(jiǎn)單易懂,需要的朋友參考下2017-01-01jquery根據(jù)屬性和index來(lái)查找屬性值并操作
這篇文章主要介紹了jquery如何根據(jù)屬性和index來(lái)查找屬性值并操作,需要的朋友可以參考下2014-07-07jQuery Ajax請(qǐng)求狀態(tài)管理器打包
現(xiàn)在的網(wǎng)站,在一個(gè)網(wǎng)頁(yè)中有異步請(qǐng)求甚至許多個(gè)異步請(qǐng)求已經(jīng)不足為奇。Ajax已經(jīng)成為了現(xiàn)在網(wǎng)站必須的基本功能,使網(wǎng)頁(yè)應(yīng)用更接近于桌面應(yīng)用2012-05-05騰訊與新浪的通過(guò)IP地址獲取當(dāng)前地理位置(省份)的接口
通過(guò)IP地址獲取當(dāng)前地理位置(省份)的接口,方便大家可以直接使用結(jié)合自己的系統(tǒng)。2010-07-07