最近写了点小东西一个滑动验证
<em><html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{
background: #000000;
}
.sliding{
width: 400px;
height: 40px;
margin: 50px auto;
background: #ccc;
text-align: center;
line-height: 40px;
position: relative;
}
.sliding > p{
width: 0px;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: green;
z-index: 99;
color: #FFFFFF;
text-align: center;
overflow: hidden;
}
.sliding > span{
display: block;
width: 46px;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-size: cover;
cursor: pointer;
z-index: 999;
}
.span1_back{
background: url(img/sli1.png) no-repeat center center;
}
.span2_back{
background: url(img/sli2.png)no-repeat center center;
}
</style>
</head>
<body>
<p class="sliding">
请按住滑块,拖至最右侧。
<p></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/11176">
<img src="https://img.php.cn/upload/webcode/000/000/008/176520781128029.jpg" alt="网趣购物系统加强升级版">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/11176">网趣购物系统加强升级版</a>
<p>新版本程序更新主要体现在:完美整合BBS论坛程序,用户只须注册一个帐号,即可全站通用!采用目前流行的Flash滚动切换广告 变换形式多样,受人喜爱!在原有提供的5种在线支付基础上增加北京云网支付!对留言本重新进行编排,加入留言验证码,后台有留言审核开关对购物系统的前台进行了一处安全更新。在原有文字友情链接基础上,增加LOGO友情链接功能强大的6种在线支付方式可选,自由切换。对新闻列表进行了调整,</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="网趣购物系统加强升级版">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/11176" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="网趣购物系统加强升级版">
</a>
</div>
<span class="span1_back">
</span>
</p>
<!-- 布局方面主要是使用定位把p标签和span都定位在 p 左边 --><br/><br/>
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$('.sliding > span').on('mousedown',function(ev){
var down_X=ev.clientX; //获取鼠标摁下的位置
var p_W=$('.sliding > p').get(0).offsetWidth; //获取p的宽度当然这其实这个可有可无
var span_X=$('.sliding > span').get(0).offsetLeft; //与上同理
$(document).get(0).onmousemove=function(ev){
var move_X=ev.clientX; //获取鼠标移动的位置
var size = move_X - down_X + p_W; //用移动过后的位置减去鼠标摁下的位置加上p的宽度或者 span 的left 值 因为俩者是同步的 所以 减去 其中一个就好
if(size>0){// 移动的时候判断size>0的时候执行,Math.min选取最小值,让拖动过程中不至于超出
size=Math.min(($('.sliding').get(0).offsetWidth - $('.sliding > span').get(0).offsetWidth),size);
}else{ //小于0的时候 size =0; 防止有无聊的用户拖回 超出边界。
size=0;
}
$('.sliding > p').css('width', size + 'px');
$('.sliding > span').css('left', size + 'px');
return false;//防止拖拽过程中选中文字
}
$(document).get(0).onmouseup=function(){ //鼠标松开执行<br/> //判段span到达边界时候执行
if(($('.sliding > span').get(0).offsetLeft) >= ($('.sliding').get(0).offsetWidth - $('.sliding > span').get(0).offsetWidth)){
$('.sliding > span').attr('class','span2_back'); //更改span的背景图片
$('.sliding > p').text('验证通过'); //更改p标签中的内容
$('.sliding > span').off('mousedown');//删除鼠标摁下方法防止用户 无聊往回 推拽
}else{//判断没到达边界让它再回到起点
$('.sliding > span').animate({left:'0px'},300); //利用jquery让p 和 span 回到起始状态
$('.sliding > p').animate({width:'0px'},300);
}
$(document).get(0).onmousemove=null; //最后让 鼠标移动 和 鼠标松开 事件停止
$(document).get(0).onmouseup=null;
}
})
})
</script>
</body>
</html></em>以上就是实现一个滑块验证功能的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号