本文實(shí)例講述了JS實(shí)現(xiàn)滑動(dòng)拼圖驗(yàn)證功能。分享給大家供大家參考,具體如下:
十載的陽春網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整陽春建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“陽春網(wǎng)站設(shè)計(jì)”,“陽春網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
先看一下效果圖:
設(shè)置畫布滑塊屬性
const l = 42, // 滑塊邊長(zhǎng) r = 10, // 滑塊半徑 w = 310, // canvas寬度 h = 155, // canvas高度 PI = Math.PI const L = l + r * 2 // 滑塊實(shí)際邊長(zhǎng)
設(shè)置背景圖片:
圖片鏈接地址可以自行更換
function getRandomImg() { return 'https://picsum.photos/300/150/?image=' + getRandomNumberByRange(0, 100) }
CSS部分代碼:
.container { width: 310px; margin: 100px auto; } #msg { width: 100%; line-height: 40px; font-size: 14px; text-align: center; } a:link, a:visited, a:hover, a:active { margin-left: 100px; color: #0366D6; } .block { position: absolute; left: 0; top: 0; } .sliderContainer { position: relative; text-align: center; width: 310px; height: 40px; line-height: 40px; margin-top: 15px; background: #f7f9fa; color: #45494c; border: 1px solid #e4e7eb; } .sliderContainer_active .slider { height: 38px; top: -1px; border: 1px solid #1991FA; } .sliderContainer_active .sliderMask { height: 38px; border-width: 1px; } .sliderContainer_success .slider { height: 38px; top: -1px; border: 1px solid #52CCBA; background-color: #52CCBA !important; } .sliderContainer_success .sliderMask { height: 38px; border: 1px solid #52CCBA; background-color: #D2F4EF; } .sliderContainer_success .sliderIcon { background-position: 0 0 !important; } .sliderContainer_fail .slider { height: 38px; top: -1px; border: 1px solid #f57a7a; background-color: #f57a7a !important; } .sliderContainer_fail .sliderMask { height: 38px; border: 1px solid #f57a7a; background-color: #fce1e1; } .sliderContainer_fail .sliderIcon { background-position: 0 -83px !important; } .sliderContainer_active .sliderText, .sliderContainer_success .sliderText, .sliderContainer_fail .sliderText { display: none; } .sliderMask { position: absolute; left: 0; top: 0; height: 40px; border: 0 solid #1991FA; background: #D1E9FE; } .slider { position: absolute; top: 0; left: 0; width: 40px; height: 40px; background: #fff; box-shadow: 0 0 3px rgba(0, 0, 0, 0.3); cursor: pointer; transition: background .2s linear; } .slider:hover { background: #1991FA; } .slider:hover .sliderIcon { background-position: 0 -13px; } .sliderIcon { position: absolute; top: 15px; left: 13px; width: 14px; height: 10px; background: url(img/tb.png) 0 -26px; background-size: 34px 471px; } .refreshIcon { position: absolute; right: 0; top: 0; width: 34px; height: 34px; cursor: pointer; background: url(img/tb.png) 0 -437px; background-size: 34px 471px; }
頁面,頁面只用放一個(gè)div就可以了
js部分代碼,包括驗(yàn)證是否正確
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript運(yùn)動(dòng)效果與技巧匯總》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。