js实现滑动滑块验证登录的具体代码
4.结束,松开按钮,按钮不可再次拖动
if(flag)return;
btn.onmousedown=null;
bg.style.width=moveX+"px";//背景
3.js事件
.bg{
width: 100%;
window.onload=function(){
}
var btn=document.querySelector(".btn"); //原生写法1.按钮按下并移动
btn.onmousemove=null;
color: black;
position: absolute;
position: relative;
if(flag)return;
bg.style.width=0;//背景
1)
if(moveX>-2){
height: 100%;
this.style.left=moveX+"px";//将移动值赋值给滑块

// var box=$(".box"),btn=$(".btn").....;
// };
/*-webkit-margin-before: 1em;
btn.onmousemove=function(e){//拖动
2.事件状态:event对象(鼠标位置)event.clientX获得与X轴的距离
text.style.color="white";
}
1.html代码
或者使用封装选择器
//获取方法集合,可直接通过id, 类, 类型, 属性, 属性值等来选取元素(返回此名字的第一个)。
//移动范围
btn.onmousedown=function(e){//按下

flag=true;
}
<!--背景-->
需要根据层级设置z-index保证滑动的正常使用
var text=document.querySelector(".text");
position: absolute;

left: 20px;
//事件清除
var bg=document.querySelector(".bg");
<a href="#" ><div>>></div></a>
text.style.color="white";
根据移动的值:判断按钮是否可以正常移动,判断按钮是否已经完成验证
<div>bg.style.width=moveX+"px";//背景
flag=true;
line-height: 34px;
var box=document.querySelector(".box");
background-color: yellowgreen;
var bg=document.querySelector(".bg");
//封装选择器
分析使用过程:按住滑块并拖动可以移动,中途松开滑块返回起始位置,拖动至最后滑块不动
this.style.left=0;//将移动值赋值给滑块
top: 0;
// var e=event||window.event;
background: #e8e8e8;
border-radius: 4px;
border: 1px solid #ccc;
width: 40px;
}
z-index: 1;
2.css样式
btn.onmousedown=null;
<p>拖动滑块验证</p>
分析动作:
3.松开按钮回到原处
}
var downX=e.clientX; //按下后对x轴的距离
this.style.left=moveX+"px";//将移动值赋值给滑块
btn.onmousemove=null;
<!--滑块-->
<!--文字-->
background-color: #fff;
text-align: center;
//事件清除
最大的盒子相对定位,其他内部内容绝对定位
回到原处清除拖动
bg.style.width=0;//背景
btn.onmouseup=function(){//移动范围
var flag=false;
btn.onmousemove=function(e){text-align: center;
.btn{
</div>
height: 34px;
if(moveX>=(box.offsetWidth-btn.offsetWidth)){//包含原始宽度内边距边框,不包含外边框
4)松开按钮
按下后获得与x轴的距离
//事件清除
.text{
var text=document.querySelector(".text");
margin: 0;
//document.querySelector(".btn").onmousedown=function(event){//event事件状态
<div></div>
样式
}
//按下onmousedown 拖动onmousemove
var moveX=e.clientX-downX; //拖动后与x轴距离减去初始值距离,移动值
if(moveX>=(box.offsetWidth-btn.offsetWidth)){//包含原始宽度内边距边框,不包含外边框
// console.log(moveX);
var box=document.querySelector(".box");
// console.log(downX);
border-radius: 4px;
};
4.效果
this.style.left=0;//将移动值赋值给滑块
function $(name){}
拖动后获得与x轴距离减去初始值距离得到按钮移动的值
text.innerHTML="验证成功";
}
width: 300px;
display: block;
// alert("1");
//松开按钮
//拖到头,验证成功
if(moveX>-2){
.box{var btn=document.querySelector(".btn");
line-height: 32px;
3)拖动
// function $(name){
btn.onmouseup=function(){
height:32px;
}
z-index: 3;
position: absolute;
}
btn.onmousedown=function(e){return document.querySelector(name);
//拖到头,验证成功
// return document.querySelector(name);
btn.onmousemove=null;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
var downX=e.clientX;
z-index: 2;
btn.onmousemove=null;
text.innerHTML="验证成功";
var moveX=e.clientX-downX;
-webkit-margin-after: 1em;*/
}
5.源码
//事件清除
2)按下
}
// console.log(moveX);
var box=$(".box"),btn=$(".btn").....;
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jz/wp/4997.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
ludou_se_only); } add_action(s
时间:2021-01-23
-
所以经常导致输错密码的
时间:2021-01-23
-
WordPress措施打开速度慢的
时间:2021-01-22
-
WordPress回覆评论自动添加
时间:2021-01-22
-
我们可以通过下面的代码
时间:2021-01-22
-
如何修改WordPress默认脚色
时间:2021-01-20
-
同样的修改文件就行
时间:2021-01-20
-
少数善意的转载者既使没
时间:2021-01-20
热门文章
-
WordPress新手安装教程(图文)
时间:2020-12-28
-
在设置菜单中增加WordPress私密 隐藏的全部
时间:2021-01-10
-
WordPress博客程序常见错误的解决方法
时间:2020-12-28
-
WordPress程序打开速度慢的三种解决方法
时间:2021-01-10
-
wordpress使用代码在每篇文章尾部添加版权
时间:2020-12-14
-
WordPress博客措施常见错误的办理要领
时间:2021-01-15
-
关于WordPress的SEO优化相关的一些PHP页面脚
时间:2021-01-07
-
WordPress措施打开速度慢的三种办理要领
时间:2021-01-22
-
详解WordPress中的头像缓存和署理中的缓存
时间:2021-01-15
-
少数善意的转载者既使没有看到版权信息
时间:2021-01-20
