日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

前端JS——滑动滑块验证登录(源码及效果)

發布時間:2025/3/21 HTML 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端JS——滑动滑块验证登录(源码及效果) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

源碼:

<!doctype html> <html lang="en"><head><meta charset="UTF-8"><meta name="Generator" content="EditPlus?"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""><title>Document</title><style>.box{position: relative;width: 300px;height: 34px;background: #e8e8e8;border-radius: 4px;left: 20px; } .btn{position: absolute;top: 0;width: 40px;height:32px;text-align: center;line-height: 32px;border-radius: 4px;z-index: 3;background-color: #fff;border: 1px solid #ccc;color: black;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; } .text{position: absolute;width: 100%;margin: 0;text-align: center;line-height: 34px;display: block;z-index: 2;/*-webkit-margin-before: 1em;-webkit-margin-after: 1em;*/-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; } .bg{position: absolute;height: 100%;background-color: yellowgreen;z-index: 1; }</style></head><body><div class="box"><!--滑塊--><div id="a" class="btn">>></div><!--文字--><p id="b"class="text">拖動滑塊驗證</p><!--背景--><div id="c"class="bg"></div> </div></body><script>//原生寫法 window.onload=function(){var btn=document.querySelector(".btn");var box=document.querySelector(".box");var bg=document.querySelector(".bg");var text=document.querySelector(".text");a.onmouseover = function(){this.style.cursor = 'pointer';}b.onmouseover = function(){this.style.cursor = 'pointer';}c.onmouseover = function(){this.style.cursor = 'pointer';}//封裝選擇器 // function $(name){ // return document.querySelector(name); // }; // var box=$(".box"),btn=$(".btn").....;var flag=false;//按下onmousedown 拖動onmousemove//document.querySelector(".btn").onmousedown=function(event){//event事件狀態 // var e=event||window.event;//獲取方法集合,可直接通過id, 類, 類型, 屬性, 屬性值等來選取元素(返回此名字的第一個)。btn.onmousedown=function(e){//按下var downX=e.clientX; //按下后對x軸的距離 // console.log(downX); // alert("1");btn.onmousemove=function(e){//拖動var moveX=e.clientX-downX; //拖動后與x軸距離減去初始值距離,移動值 // console.log(moveX);//移動范圍if(moveX>-2){this.style.left=moveX+"px";//將移動值賦值給滑塊bg.style.width=moveX+"px";//背景if(moveX>=(box.offsetWidth-btn.offsetWidth)){//包含原始寬度內邊距邊框,不包含外邊框//拖到頭,驗證成功flag=true;text.innerHTML="驗證成功";text.style.color="white";//事件清除btn.onmousedown=null;btn.onmousemove=null;}}}}//松開按鈕btn.onmouseup=function(){ //事件清除btn.onmousemove=null;if(flag)return;this.style.left=0;//將移動值賦值給滑塊bg.style.width=0;//背景} }</script> </html>

總結

以上是生活随笔為你收集整理的前端JS——滑动滑块验证登录(源码及效果)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。