最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

js實(shí)現(xiàn)滑塊解鎖

標(biāo)簽:
Html/CSS Html5 JavaScript

效果图1:

https://img1.sycdn.imooc.com//5b7a65200001174303870066.jpg

效果图2:

https://img1.sycdn.imooc.com//5b7a65200001e64d04570381.jpg

<!DOCTYPE html>
<html>
<head>
<title>滑块验证</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#container{
padding: 0;
margin: 0;
position: relative;
width:350px;
height: 50px;
border: 1px solid gray;
border-radius: 3px;
margin: 10px auto;
line-height: 50px;
user-select:none;
}
#success,#mark,#move{
position: absolute;
width: 100%;
height: 100%;
font-size: 20px;
font-weight: bold;
text-align: center;
color: white;
}
#success{
background: lightgreen;
}
#mark{
background:gray;
}
#move{
width: 50px;
background: white;
color: black;
top: 0;
left: 0;
cursor: move;
}
</style>
</head>
<body>
<div id="container">
<div id="success">success!</div>
<div id="mark">please,slide!</div>
<div id="move">&gt;&gt;</div>
</div>
<script type="text/javascript">
let move=document.getElementById('move'),
mark=document.getElementById('mark'),
container=document.getElementById('container'),
distance=container.getBoundingClientRect().width,//总长度
isstop=false,//是否到达终点
offL=container.offsetLeft,//容器左边距
moveL=null,//滑块左边距
scale=null;//渐变进度
move.onmousedown=function(event){
move.onmousemove=function(event){
move.style.transform='';
moveL=event.clientX-offL-25,//让鼠标在滑块中间
scale=((moveL+25)/3.5)+'%';//左边距和总长度比率
if(moveL>distance-50){  
isstop=true;
return;//返回不再执行下面的语句
}
move.style.setProperty('left',moveL+'px');
mark.style.setProperty('background',`linear-gradient(to right,
lightblue 0%,
lightblue ${scale},
gray ${scale},
gray 100%)`);
}
}
document.onmouseup=function(){//move不准确
if(isstop){
mark.style.setProperty('display','none');
move.innerText='√'
setTimeout(()=>{alert('success!')},200);
move.onmousedown=null;
move.onmousemove=null;
       document.onmouseup=null;
}else{
move.style.transform=`translateX(${-moveL}px)`;
mark.style.background='gray';
//mark.style.transition='all .5s';//因颜色过渡出现了底层的青色
move.onmousemove=null;
}
}
</script>
</body>
</html>
點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消