拖动验证码插件

拖动验证码插件

效果图:

在验证前,提交弹出验证失败,验证后弹出验证成功。

文件结构:

css:

#drag{
    position: relative;
    background-color: #e8e8e8;
    width: 300px;
    height: 34px;
    line-height: 34px;
    text-align: center;
}
#drag .handler{
    position: absolute;
    top: 0px;
    left: 0px;
    width: 40px;
    height: 32px;
    border: 1px solid #ccc;
    cursor: move;
}
.handler_bg{
    background: #fff url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTEyNTVEMURGMkVFMTFFN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D8uZw+kUoDYEYgloMIvgHg/EM/ptHx0EFk9I8wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==") no-repeat center;
}
#drag .drag_bg{
    background-color: #7ac23c;
    height: 34px;
    width: 0px;
}
#drag .drag_text{
    position: absolute;
    top: 0px;
    width: 300px;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
    -o-user-select:none;
    -ms-user-select:none;
}

#submits{border: 0;width: 200px;margin-top: 50px;height: 40px;}
#submits:hover{background: #7ac23c;}

darg.js:

(function($){
    $.fn.drag = function(options){
        var x, drag = this, isMove = false, defaults = {
        };
        var options = $.extend(defaults, options);
        //添加背景,文字,滑块
        var html = ‘<div class="drag_bg"></div>‘+
                    ‘<div class="drag_text" onselectstart="false" unselectable="on">拖动滑块验证</div>‘+
                    ‘<div class="handler handler_bg"></div>‘;
        this.html(html);

        var handler = drag.find(‘.handler‘);
        var drag_bg = drag.find(‘.drag_bg‘);
        var text = drag.find(‘.drag_text‘);
        var maxWidth = drag.width() - handler.width();  //能滑动的最大间距

        //鼠标按下时候的x轴的位置
        handler.mousedown(function(e){
            isMove = true;
            x = e.pageX - parseInt(handler.css(‘left‘), 10);
        });

        //鼠标指针在上下文移动时,移动距离大于0小于最大间距,滑块x轴位置等于鼠标移动距离
        $(document).mousemove(function(e){
            var _x = e.pageX - x;
            if(isMove){
                if(_x > 0 && _x <= maxWidth){
                    handler.css({‘left‘: _x});
                    drag_bg.css({‘width‘: _x});
                }else if(_x > maxWidth){  //鼠标指针移动距离达到最大时清空事件
                    dragOk();
                    aaa(true);
                }
            }
        }).mouseup(function(e){
            isMove = false;
            var _x = e.pageX - x;
            if(_x < maxWidth){ //鼠标松开时,如果没有达到最大距离位置,滑块就返回初始位置
                handler.css({‘left‘: 0});
                drag_bg.css({‘width‘: 0});
            }
        });

        //清空事件
        function dragOk(){
            handler.removeClass(‘handler_bg‘).addClass(‘handler_ok_bg‘);
            text.text(‘验证通过‘);
            text.attr("onselectstart","true");
            drag.css({‘color‘: ‘#fff‘});
            handler.unbind(‘mousedown‘);
            $(document).unbind(‘mousemove‘);
            $(document).unbind(‘mouseup‘);
        }
    };
})(jQuery);

html:

<!DOCTYPE html>
<html>
<head>
<title>jQuery仿淘宝网拖动滑块验证码代码</title>
<meta charset="utf-8">
<link href="css/drag.css" rel="stylesheet" type="text/css">
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/drag.js" type="text/javascript"></script>
</head>
<body>

<center><br><br><br><div id="drag"></div></center>

<center><button id="submits">提交</button></center>

<script type="text/javascript">
$(‘#drag‘).drag();
$(‘#submits‘).click(function () {
    if($(‘.drag_text‘).attr("onselectstart")=="true"){
        alert("验证成功")
    }else {
        alert("验证失败")
    }
});
</script>

<div style="text-align:center;margin:50px 0; font:normal 14px/24px ‘MicroSoft YaHei‘;">
<p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.</p>
</div>
</body>
</html>

参考自:http://www.lanrenzhijia.com/jquery/3338.html

时间: 2024-11-01 16:24:24

拖动验证码插件的相关文章

kaptcha验证码插件

发现现在程序员越来越懒了,连验证码都不想自己写了. https://code.google.com/p/kaptcha/downloads/list kaptcha验证码插件,码迷,mamicode.com

(HTTP)金牌信通V8-生意虎信验证码插件

金牌信通V8-生意虎信验证码插件 (HTTP) 客户接口说明 1 第一章  发送接口 2 1.1 请求地址 2 1.2参数说明 2 1.3返回值 2 第二章 余额及已发送量查询接口 3 2.1 请求地址 3 2.2参数说明 3 2.3返回值 3 第三章 非法关键词查询 4 3.1 请求地址 4 3.2参数说明 4 3.3返回值 4 第四章 状态报告接口 5 4.1 请求地址 5 4.2参数说明 5 4.3返回值 5 4.4错误返回值--状态报告请求错误返回格式及对应值 6 第五章 上行接口 6

完美验证码识别系统,验证码插件使用帮助文档

该验证码插件为<完美验证码识别系统V3.2.1>的python封装,提供给UiBot实现需验证码识别的场景的解决方案. 载入识别库 LoadDat(datPath, password) 函数说明:        从文件中载入识别库文件,成功返回True,否则返回False. 参数: 参数名 类型 说明 datPath 文本型 识别库文件所在全路径 password 文本型 识别库调用密码 返回值: 返回结果 类型 说明 True boolean型 载入识别库成功 False boolean型

django入门6引入验证码插件 django-simple-captcha

Django的验证码插件 https://github.com/mbi/django-simple-captcha 安装 (mxonline) C:\Users\ws>pip install  django-simple-captcha==0.4.6 添加到settings.py中 配置urls.py 创建数据表 [email protected] > makemigrations [email protected] > migrate 在forms中引用 Views中定义 页面中引用

可以拖动的插件

1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 <link rel="stylesheet" href="左边选项卡/css/bootstrap.min.css"/> 7 8 <style> 9 *{

js实现拖动验证码

效果图: Index.html <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8" /> <meta name="viewport"

锋利的jQuery-7--query ui效果库--拖动排序插件sortable

一个简单的拖动排序效果,具体请参看jQuery ui官网demo. jquery ui :http://jqueryui.com/ sortable例子:http://jqueryui.com/sortable/#portlets 效果如图: html代码: <style type="text/css"> #myList{width: 80px;background: #EEE;padding: 5px;list-style: none;} #myList a{text-d

Django学习系列之captcha 验证码插件

安装部署 安装captcha pip3.6 install django-simple-captcha==0.4.6 settings.py中引入captcha INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.st

利用 canvas 破解 某拖动验证码

案例: https://www.capy.me/products/  whois 查询发现应该是一个日本公司出的. 测试:尼玛,点来点去原来就4张图片来来回回切换,专业点好不好...... Part 1 识别 读取原图: 随便多刷新几次,读两张图片,用 PS 补成原图. 对比图片:利用canvas的特性 getImageData 读取像素,然后和你想要识别的图片对比,找出被挖出去的部分. 计算补全: 然后就简单啦,计算好被挖出部分在x 和 y 方向的偏移量,然后把 小图移动过去,OK 搞定...