jq实现简单的滑动解锁效果

本文介绍了一种使用HTML、CSS及jQuery实现的滑动解锁效果。该效果通过鼠标拖动操作来触发验证流程,当滑块移动到指定位置时显示验证通过的信息。此方法适用于网页互动设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>滑动解锁</title>
    <style>
        *{
            margin:0;
            padding: 0;
            box-sizing: border-box;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
        .outer{
            position: relative;
            margin:20px auto;
            width: 200px;
            height: 30px;
            line-height: 28px;
            border:1px solid #ccc;
            background: #ccc9c9;
        }
        .outer span,.filter-box,.inner{
            position: absolute;
            top: 0;
            left: 0;
        }
        .outer span{
            display: block;
            padding:0  0 0 36px;
            width: 100%;
            height: 100%;
            color: #fff;
            text-align: center;
        }
        .filter-box{
            width: 0;
            height: 100%;
            background: green;
            z-index: 9;
        }
        .outer.act span{
            padding:0 36px 0 0;
        }
        .inner{
            width: 36px;
            height: 28px;
            text-align: center;
            background: #fff;
            cursor: pointer;
            font-family: "宋体";
            z-index: 10;
            font-weight: bold;
            color: #929292;
        }
        .outer.act .inner{
            color: green;
        }
        .outer.act span{
            z-index: 99;
        }
    </style>
    <script src="js/jquery-1.11.3.min.js"></script>
    <script>
        $(function(){
            $(".inner").mousedown(function(e){
                var el = $(".inner"),os = el.offset(),dx,$span=$(".outer>span"),$filter=$(".filter-box");
                $(document).mousemove(function(e){
                    dx = e.pageX - os.left;
                    if(dx<0){
                        dx=0;
                    }else if(dx>162){
                        dx=162
                    }
                    $filter.css('width',dx);
                    el.css("left",dx);
                });
                $(document).mouseup(function(e){
                    $(document).off('mousemove');
                    dx = e.pageX - os.left;
                    if(dx<162){
                        dx=0;
                        $span.html("滑动解锁");
                    }else if(dx>=162){
                        dx=162;
                        $(".outer").addClass("act");
                        $span.html("验证通过!");
                        el.html('&radic;')
                    }
                    $filter.css('width',dx);
                    el.css("left",dx)
                })
            })
        })
    </script>
</head>
<body>
    <div class="outer">
        <div class="filter-box"></div>
        <span>
            滑动解锁
        </span>
        <div class="inner">&gt;&gt;</div>
    </div>
</body>
</html>

 

转载于:https://www.cnblogs.com/dongxiaolei/p/7930198.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值