JavaScript實(shí)現(xiàn)登錄滑塊驗(yàn)證
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)登錄滑塊驗(yàn)證的具體代碼,供大家參考,具體內(nèi)容如下
html代碼
<div class="login-select"> <div v-show="errselectFlag" id="err-select"></div> <p id="title-p">按住滑塊,拖拽驗(yàn)證</p> <div id="left-select"></div> <div id="right-select"> <i id="icon-dui" class="iconfont icon-right"></i> </div> </div>
javascript代碼
// 滑塊驗(yàn)證 var oRight = document.getElementById("right-select"); var bg = document.getElementById("left-select"); var title = document.getElementById("title-p"); var i = document.getElementById("icon-dui"); oRight.onmousedown = function (e) { var downX = e.clientX; //按下按鈕后與窗口的x軸間距 // 鼠標(biāo)移動(dòng)事件 oRight.onmousemove = function (e) { if (e.clientX != 240) { oRight.style.left = 0 + "px"; bg.style.left = 0 + "px"; } var moveX = e.clientX - downX; //滑動(dòng)的時(shí)候距離窗口的x軸的間距 //只有在大于0的時(shí)候才拖動(dòng),否則會(huì)出現(xiàn)反向拖動(dòng) if (moveX > 0) { oRight.style.left = moveX + "px"; //滑塊與左邊的距離 bg.style.width = moveX + "px"; //背景的寬度就是滑塊距離左邊的位置 if (moveX >= 280 - oRight.offsetWidth) { i.className = "iconfont icon-xingzhuang"; i.style.color = "rgb(86, 192, 15)"; title.innerText = "驗(yàn)證通過"; title.style.color = "#fff"; oRight.onmousemove = null; oRight.onmousedown = null; } } }; };
style代碼
注:樣式為sass文件
*{margin: 0;padding: 0;box-sizing: border-box;} .login-select { width: 280px; height: 40px; margin: auto; margin-top: 20px; margin-left: 15px; margin-right: 15px; text-align: center; line-height: 40px; background: rgba(134, 134, 131, 0.6); display: flex; position: relative; #err-select { width: 138px; height: 38px; position: absolute; right: -152px; top: 0; color: #fff; font-size: 12px; border-radius: 5px; line-height: 38px; text-align: center; background: rgb(177, 71, 71); } #title-p { text-align: center; line-height: 40px; width: 100%; height: 100%; font-size: 14px; position: absolute; } #left-select { width: 0; height: 100%; transform: translate(0.3s); background: rgb(86, 192, 15); } #right-select { width: 40px; height: 40px; background: #fff; color: #aaaa; text-align: center; line-height: 40px; border: 1px solid #ccc; position: absolute; cursor: move; } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序?qū)崿F(xiàn)的點(diǎn)擊按鈕 彈出底部上拉菜單功能示例
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)的點(diǎn)擊按鈕 彈出底部上拉菜單功能,結(jié)合實(shí)例形式分析了action-sheet組件及事件響應(yīng)簡(jiǎn)單使用技巧,需要的朋友可以參考下2018-12-12IE下雙擊checkbox反應(yīng)延遲問題的解決方法
這篇文章主要介紹了IE下雙擊checkbox反應(yīng)延遲問題的解決方法,需要的朋友可以參考下2014-03-03JavaScript原生對(duì)象之String對(duì)象的屬性和方法詳解
這篇文章主要介紹了JavaScript原生對(duì)象之String對(duì)象的屬性和方法詳解,本文講解了length、charAt()、charCodeAt()、concat()、indexOf()、lastIndexOf()等方法屬性,需要的朋友可以參考下2015-03-03javascript:json數(shù)據(jù)的頁面綁定示例代碼
本篇文章主要是對(duì)javascript:json數(shù)據(jù)的頁面綁定示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-01-01JavaScript下通過的XMLHttpRequest發(fā)送請(qǐng)求的代碼
JavaScript下通過的XMLHttpRequest發(fā)送請(qǐng)求的代碼,需要的朋友可以參考下。2011-06-06原生JS實(shí)現(xiàn)循環(huán)Nodelist Dom列表的4種方式示例
這篇文章主要介紹了原生JS實(shí)現(xiàn)循環(huán)Nodelist Dom列表的4種方式,結(jié)合具體實(shí)例形式分析了javascript循環(huán)遍歷Nodelist Dom列表的常用操作技巧,需要的朋友可以參考下2018-02-02