滑动拼图验证码

这里写自定义目录标题

图片验证码

拖动滑块完成拼图的验证

代码

html
    <div class="comImageValidate rightValidate">
        <div class="imgBg_2"></div>
        <div class="imgBg_3"></div>
        <div style="width: 100%; height: 30px;"></div>
        <div class="imgBg">
            <div class="imgBtn">
                <img alt="" src="">
            </div>
            <span class="refresh">
        	<img alt="" src="">
        </span>
        </div>

        <div class="hkinnerWrap" style="height:30px; position: relative">
            <span class="v_rightBtn "><em class="notSel">→</em></span>
            <span class="huakuai" style="font-size: 12px;line-height: 33px;color: #A9A9A9;">向右滑动滑块填充拼图完成验证</span>
            <input type="hidden" name="validX" />
        </div>

    </div>
js
//拼图位置
var y = "";
var x = "";

$(".comImageValidate").ready(function() {
    validateImageInit();
    $(".refresh").click(function() {
        validateImageInit();
    })
    $(".hkinnerWrap").mouseover(function() {
        $(".imgBg").css("display", "block");
        $(".refresh").css("display", "block");
    }).mouseleave(function() {
        $(".imgBg").css("display", "block");
        $(".refresh").css("display", "block");
    });

    $(".imgBg").mouseover(function() {
        $(".imgBg").css("display", "block");
        $(".refresh").css("display", "block");
    }).mouseleave(function() {
        $(".imgBg").css("display", "block");
        $(".refresh").css("display", "block");
    });

    $('.v_rightBtn').on({
        mousedown: function(e) {
            $(".huakuai").html("");
            $(".hkinnerWrap").removeClass("red green")
            var el = $(this);
            var os = el.offset();
            dx = e.pageX - os.left;
            //$(document)
            $(this).parents(".hkinnerWrap").off('mousemove');
            $(this).parents(".hkinnerWrap").on('mousemove', function(e) {
                var newLeft = e.pageX - dx;
                el.offset({
                    left: newLeft
                });
                var newL = parseInt($(".v_rightBtn").css("left"));
                if (newL <= 0) {
                    newL = 0;
                } else if (newL >= 240) {
                    newL = 240;
                }
                $(".v_rightBtn").css("left", newL + "px");
                $(".imgBtn").offset({
                    left: newLeft
                });
                $(".imgBtn").css("left", newL + "px")
            }).on('mouseup', function(e) {
                //$(document)
                $(this).off('mousemove');
            })
        }
    }).on("mouseup", function() {
        $(this).parents(".hkinnerWrap").off('mousemove');
        var l = $(this).css("left");
        if (l.indexOf("px") != -1) {
            l = l.substring(0, l.length - 2);
        }
        x = l;


        submitDate(l,y, tokenId)
    })

});
/*获取验证码*/
            validateImageInit: function() {
                var that = this
                this.send({
                    url: window.BAOSIGHT.API.MEMBER.GET_IMG_CODE,
                    data: {},
                    success: function(data) {
                        var type = data.type;
                        console.log(type);
                        switch ("slide") {
                            case "operation":
                                that.initOperationVerificationCode(data);
                                break;
                            case "char":
                                that.initCharVerificationCode(data);
                                break;
                            case "slide":
                                that.initSlideVerificationCode(data, that);
                                break;
                            default:
                                console.log("验证码错误");
                                break;
                        }
                    },
                    error: function(err) {
                        this.validateImageInit();
                    }
                })
            },

            initOperationVerificationCode: function(data) {
                $(".imgBg_3").css("background", '#fff url("data:image/jpg;base64,' + data.operationImage + '")');
            },

            initSlideVerificationCode: function(data, that) {
                that.variate.tokenId = data.data.randomKey;
                that.variate.y = data.data.y;
                $(".huakuai").html("向右滑动滑块填充拼图");
                $(".imgBg").css("background", '#fff url("data:image/jpg;base64,' + data.data.shadeImage + '")');
                $(".imgBtn").css('top', data.data.y + "px");
                $(".imgBtn").find("img").attr("src", "data:image/png;base64," + data.data.cutoutImage)
                $(".hkinnerWrap").removeClass("red green");
                $(".v_rightBtn").css("left", 0);
                $(".imgBtn").css("left", 0);
            },

            initCharVerificationCode: function(data) {
                $(".imgBg_2").css("background", '#fff url("data:image/jpg;base64,' + data.data.charImage + '")');
                $(".imgBg_3").css("none");
            },
            /*图形验证*/
            submitDate: function(x, y, tokenId) {
                var that = this
                that.send({
                        url: window.BAOSIGHT.API.MEMBER.CHECK_IMG_CODE,
                        data: {
                            x: x,
                            y: y,
                            randomKey: tokenId
                        },
                        success: function(data) {
                            if (data.data == true) {
                                $(".hkinnerWrap").addClass("green").removeClass("red");
                                $(".hkinnerWrap input[name='validX']").val(x);
                                $("#x").val(x);
                                $("#y").val(y);
                                layer.msg("验证成功", { time: 1000, icon: 1 })
                            } else {
                                $(".hkinnerWrap").addClass("red").removeClass("green");
                                setTimeout(function() {
                                    $(".hkinnerWrap").removeClass("red green");
                                    $(".v_rightBtn").css("left", 0);
                                    $(".imgBtn").css("left", 0);
                                }, 280)
                                that.validateImageInit();
                            }
                        },
                        error: function(msg) {
                            that.showTips(false, msg)
                        }
                    })
                  
            }
CSS
	.rightValidate {
        width: 280px;
        margin: 0px auto;
        position: relative;
        line-height: 30px;
        height: 30px;
        text-align: center;
        z-index: 99;
        margin-top: 60px;
    }
    
    .v_rightBtn {
        position: absolute;
        left: 0;
        top: 0;
        height: 33px;
        width: 40px;
        background: #ddd;
        cursor: pointer;
    }
    
    .imgBtn {
        width: 44px;
        height: 171px;
        position: absolute;
        left: 0;
    }
    
    .imgBtn img {
        z-index: 99;
        text-align: center;
    }
    
    .imgBg {
        position: absolute;
        bottom: 35px;
        width: 280px;
        height: 171px;
        display: block;
        z-index: 9;
    }
    
    .imgBg_2 {
        position: absolute;
        bottom: -80px;
        bottom: 35px;
        width: 150px;
        height: 60px;
        display: block;
        z-index: 9;
    }
    
    .imgBg_3 {
        position: absolute;
        bottom: -80px;
        bottom: 35px;
        width: 170px;
        height: 60px;
        display: block;
        z-index: 9;
    }
    
    .hkinnerWrap {
        border: 1px solid #eee;
        z-index: 9999
    }
    
    .green {
        border-color: #34C6C2 !important;
    }
    
    .green .v_rightBtn {
        background: #34C6C2;
        color: #fff;
    }
    
    .red {
        border-color: red !important;
    }
    
    .red .v_rightBtn {
        background: red;
        color: #fff;
    }
    
    .refresh {
        position: absolute;
        width: 30px;
        height: 30px;
        right: 4px;
        top: 4px;
        font-size: 12px;
        color: #fff;
        text-shadow: 0px 0px 9px #333;
        cursor: pointer;
        display: none;
    }
    
    .notSel {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -webkit-touch-callout: none;
    }
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
滑动拼图验证码在小红书中的应用类似于其他网站。滑动拼图验证码是一种人机验证机制,通过用户拖动滑块将缺口对齐,以证明用户是真实的人类,而不是自动化程序或恶意机器人。 具体到小红书的实现,根据引用中提供的代码,可以看到它使用了一个名为`slideverify`的自定义组件。这个组件接受一些参数,如滑块宽度、滑块高度、滑块位置等,并提供了一些回调函数,如`onSuccess`、`onRefresh`等。 其中,`getImageVerifyCode`函数用于获取验证码图片,并将图片的地址赋值给`imgurl`和`miniimgurl`。`imgurl`存储原始大小的验证码图片地址,`miniimgurl`存储缩略图的验证码图片地址。 `onRefresh`函数用于刷新验证码,它会清空`imgurl`和`miniimgurl`的值,并重新调用`getImageVerifyCode`函数获取新的验证码图片。 `onSuccess`函数在滑动结束后,将滑动的距离作为参数传入,并调用`verifyImageCode`函数进行后台验证。根据后台返回的验证结果,如果通过则显示成功信息,否则显示错误信息,并调用`onRefresh`函数刷新验证码。 总的来说,滑动拼图验证码在小红书中的实现是通过自定义组件和一些回调函数来完成的,它增加了用户与机器的交互,提高了系统的安全性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue实现滑动拼图验证码功能](https://download.csdn.net/download/weixin_38747917/14818686)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [3分钟使用Halcon识别网易滑块拼图验证码](https://blog.csdn.net/qq_29888333/article/details/84192678)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Java Vue uni-app 三端实现滑动拼图验证码](https://blog.csdn.net/qq_32698323/article/details/118876646)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值