<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5">
    <title>HTML5实现滑动验证码 | 云图网</title>
    <meta name="keywords" content="App,CSS,go,html,https,JavaScript,Qt,UML,Web">
<meta name="description" content="在前面的一篇文章中，我详细的分析了滑动验证码的实现原理。在本文中，我们在通过实现滑动验证码的案例和代码进一步加深理解。 我们先来看一下最终的实现效果： 滑动验证码实现过程 先实现一个div，内容便是&ldquo;拖动滑块验证&rdquo;，设置其不可框选。背景为灰色。 在编写一个div，宽为滑块的宽度。背景为向右的箭头…">
<meta property="og:type" content="article">
<meta property="og:url" content="https://blog.ytso.com/tech/aiops/251189.html">
<meta property="og:site_name" content="云图网">
<meta property="og:title" content="HTML5实现滑动验证码">
<meta property="og:image" content="http://img.bbs.csdn.net/upload/201703/12/1489306602_365510.png">
<meta property="og:description" content="在前面的一篇文章中，我详细的分析了滑动验证码的实现原理。在本文中，我们在通过实现滑动验证码的案例和代码进一步加深理解。 我们先来看一下最终的实现效果： 滑动验证码实现过程 先实现一个div，内容便是&ldquo;拖动滑块验证&rdquo;，设置其不可框选。背景为灰色。 在编写一个div，宽为滑块的宽度。背景为向右的箭头…">
<link rel="canonical" href="https://blog.ytso.com/tech/aiops/251189.html">
<meta name="applicable-device" content="pc,mobile">
<meta http-equiv="Cache-Control" content="no-transform">
<link rel="shortcut icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg">
<link rel='dns-prefetch' href='//cdnjs.cloudflare.com' />
<style id='wp-img-auto-sizes-contain-inline-css' type='text/css'>
img:is([sizes=auto i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}
/*# sourceURL=wp-img-auto-sizes-contain-inline-css */
</style>
<link rel='stylesheet' id='stylesheet-css' href='https://blog.ytso.com/wp-content/themes/justnews/css/style.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='material-icons-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/material-icons.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='remixicon-css' href='https://cdnjs.cloudflare.com/ajax/libs/remixicon/4.2.0/remixicon.min.css?ver=6.9.4' type='text/css' media='all' />
<link rel='stylesheet' id='font-awesome-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/font-awesome.css?ver=6.21.5' type='text/css' media='all' />
<style id='wp-block-library-inline-css' type='text/css'>
:root{--wp-block-synced-color:#7a00df;--wp-block-synced-color--rgb:122,0,223;--wp-bound-block-color:var(--wp-block-synced-color);--wp-editor-canvas-background:#ddd;--wp-admin-theme-color:#007cba;--wp-admin-theme-color--rgb:0,124,186;--wp-admin-theme-color-darker-10:#006ba1;--wp-admin-theme-color-darker-10--rgb:0,107,160.5;--wp-admin-theme-color-darker-20:#005a87;--wp-admin-theme-color-darker-20--rgb:0,90,135;--wp-admin-border-width-focus:2px}@media (min-resolution:192dpi){:root{--wp-admin-border-width-focus:1.5px}}.wp-element-button{cursor:pointer}:root .has-very-light-gray-background-color{background-color:#eee}:root .has-very-dark-gray-background-color{background-color:#313131}:root .has-very-light-gray-color{color:#eee}:root .has-very-dark-gray-color{color:#313131}:root .has-vivid-green-cyan-to-vivid-cyan-blue-gradient-background{background:linear-gradient(135deg,#00d084,#0693e3)}:root .has-purple-crush-gradient-background{background:linear-gradient(135deg,#34e2e4,#4721fb 50%,#ab1dfe)}:root .has-hazy-dawn-gradient-background{background:linear-gradient(135deg,#faaca8,#dad0ec)}:root .has-subdued-olive-gradient-background{background:linear-gradient(135deg,#fafae1,#67a671)}:root .has-atomic-cream-gradient-background{background:linear-gradient(135deg,#fdd79a,#004a59)}:root .has-nightshade-gradient-background{background:linear-gradient(135deg,#330968,#31cdcf)}:root .has-midnight-gradient-background{background:linear-gradient(135deg,#020381,#2874fc)}:root{--wp--preset--font-size--normal:16px;--wp--preset--font-size--huge:42px}.has-regular-font-size{font-size:1em}.has-larger-font-size{font-size:2.625em}.has-normal-font-size{font-size:var(--wp--preset--font-size--normal)}.has-huge-font-size{font-size:var(--wp--preset--font-size--huge)}.has-text-align-center{text-align:center}.has-text-align-left{text-align:left}.has-text-align-right{text-align:right}.has-fit-text{white-space:nowrap!important}#end-resizable-editor-section{display:none}.aligncenter{clear:both}.items-justified-left{justify-content:flex-start}.items-justified-center{justify-content:center}.items-justified-right{justify-content:flex-end}.items-justified-space-between{justify-content:space-between}.screen-reader-text{border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-wrap:normal!important}.screen-reader-text:focus{background-color:#ddd;clip-path:none;color:#444;display:block;font-size:1em;height:auto;left:5px;line-height:normal;padding:15px 23px 14px;text-decoration:none;top:5px;width:auto;z-index:100000}html :where(.has-border-color){border-style:solid}html :where([style*=border-top-color]){border-top-style:solid}html :where([style*=border-right-color]){border-right-style:solid}html :where([style*=border-bottom-color]){border-bottom-style:solid}html :where([style*=border-left-color]){border-left-style:solid}html :where([style*=border-width]){border-style:solid}html :where([style*=border-top-width]){border-top-style:solid}html :where([style*=border-right-width]){border-right-style:solid}html :where([style*=border-bottom-width]){border-bottom-style:solid}html :where([style*=border-left-width]){border-left-style:solid}html :where(img[class*=wp-image-]){height:auto;max-width:100%}:where(figure){margin:0 0 1em}html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:var(--wp-admin--admin-bar--height,0px)}@media screen and (max-width:600px){html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:0px}}
/*wp_block_styles_on_demand_placeholder:69c815b3eec69*/
/*# sourceURL=wp-block-library-inline-css */
</style>
<style id='classic-theme-styles-inline-css' type='text/css'>
/*! This file is auto-generated */
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
/*# sourceURL=/wp-includes/css/classic-themes.min.css */
</style>
<link rel='stylesheet' id='wpcom-member-css' href='https://blog.ytso.com/wp-content/plugins/wpcom-member/css/style.css?ver=1.7.19' type='text/css' media='all' />
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1" id="jquery-core-js"></script>
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1" id="jquery-migrate-js"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://blog.ytso.com/xmlrpc.php?rsd" />
<meta name='description' content='在前面的一篇文章中，我详细的分析了滑动验证码的实现原理。在本文中，我们在通过实现滑动验证码的案例和代码进一步加深理解。 我们先来看一下最终的实现效果： 滑动验证码实现过程 先实现一个div，内容便是&ldquo;…' />
<meta name='keywords' content='App,CSS,go,html,https,JavaScript,Qt,UML,Web' />
<style>:root{--theme-color: #08c; --theme-hover: #07c; --logo-height: 32px; --logo-height-mobile: 26px; --menu-item-gap: 28px; --member-login-bg: url('https://blog.ytso.com/loginwall.jpg'); --header-bg-color: #fff; --header-bg-image: none; --theme-border-radius-s: 3px; --theme-border-radius-m: 5px; --theme-border-radius-l: 8px; --theme-border-radius-xl: 12px; --thumb-ratio-default: 480 / 300; --thumb-ratio-post: 480 / 300; --post-video-ratio: 860 / 482;}</style>
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="32x32" />
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="192x192" />
<link rel="apple-touch-icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
<meta name="msapplication-TileImage" content="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
    <!--[if lte IE 11]><script src="https://blog.ytso.com/wp-content/themes/justnews/js/update.js"></script><![endif]-->
</head>
<body class="wp-singular post-template-default single single-post postid-251189 single-format-standard wp-theme-justnews lang-cn el-boxed header-fixed">
<header class="header header-fluid">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse" aria-label="menu">
                <span class="icon-bar icon-bar-1"></span>
                <span class="icon-bar icon-bar-2"></span>
                <span class="icon-bar icon-bar-3"></span>
            </button>
                        <div class="logo">
                <a href="https://blog.ytso.com/" rel="home">
                    <img src="https://imgcdn.ytso.com/wp-content/uploads/2021/12/20211207181156143.png" alt="云图网">
                </a>
            </div>
        </div>
        <div class="collapse navbar-collapse mobile-style-0">
            <nav class="primary-menu"><ul id="menu-justnews-footer-menu" class="nav navbar-nav wpcom-adv-menu"><li class="menu-item"><a href="https://blog.ytso.com/category/industrynews">业界资讯</a></li>
<li class="menu-item current-post-ancestor active menu-item-style menu-item-style-1 dropdown"><a target="_blank" href="https://blog.ytso.com/category/tech" class="dropdown-toggle">技术专区</a>
<ul class="dropdown-menu menu-item-wrap menu-item-col-5">
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/cloud">云计算</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/ai">人工智能</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/safety">信息安全</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/bigdata">大数据</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/dev">研发管理</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/webdev">大前端</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/opensource">开源</a></li>
	<li class="menu-item current-post-ancestor current-post-parent active"><a href="https://blog.ytso.com/category/tech/aiops">智能运维</a></li>
	<li class="menu-item current-post-ancestor current-post-parent active"><a href="https://blog.ytso.com/category/tech/pnotes">编程笔记</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/wp">WordPress</a></li>
</ul>
</li>
<li class="menu-item"><a href="https://blog.ytso.com/category/enterprise-strategic-planning">企业战略规划</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/download">下载专区</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/it%e6%b1%9f%e6%b9%96%e5%8f%b2">江湖史</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/notes">随笔记录</a></li>
</ul></nav>            <div class="navbar-action">
                <div class="navbar-search-icon j-navbar-search"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></div><form class="navbar-search" action="https://blog.ytso.com/" method="get" role="search"><div class="navbar-search-inner"><i class="wpcom-icon wi navbar-search-close"><svg aria-hidden="true"><use xlink:href="#wi-close"></use></svg></i><input type="text" name="s" class="navbar-search-input" autocomplete="off" maxlength="100" placeholder="输入关键词搜索..." value=""><button class="navbar-search-btn" type="submit" aria-label="搜索"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></button></div></form>                    <div id="j-user-wrap">
                        <a class="login" href="https://blog.ytso.com/login">登录</a>
                        <a class="login register" href="https://blog.ytso.com/register">注册</a>
                    </div>
                                            <a class="wpcom-btn btn-primary btn-xs publish" href="https://blog.ytso.com/contribute">
                            <i class="fa fa-edit"></i> 投稿                        </a>
                                </div>
        </div>
    </div><!-- /.container -->
</header>

<div id="wrap">    <div class="wrap container">
        <ol class="breadcrumb" vocab="https://schema.org/" typeof="BreadcrumbList"><li class="home" property="itemListElement" typeof="ListItem"><a href="https://blog.ytso.com" property="item" typeof="WebPage"><span property="name" class="hide">云图网</span>首页</a><meta property="position" content="1"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech" property="item" typeof="WebPage"><span property="name">技术专区</span></a><meta property="position" content="2"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech/aiops" property="item" typeof="WebPage"><span property="name">智能运维</span></a><meta property="position" content="3"></li></ol>        <main class="main">
                            <article id="post-251189" class="post-251189 post type-post status-publish format-standard hentry category-aiops category-pnotes tag-app tag-css tag-go tag-html tag-https tag-javascript tag-qt tag-uml tag-web entry">
                    <div class="entry-main">
                                                                        <div class="entry-head">
                            <h1 class="entry-title">HTML5实现滑动验证码</h1>
                            <div class="entry-info">
                                                                <time class="entry-date published" datetime="2022-05-02T03:19:54+08:00" pubdate>
                                    2022年5月2日 03:19                                </time>
                                <span class="dot">•</span>
                                <a href="https://blog.ytso.com/category/tech/aiops" rel="category tag">智能运维</a>, <a href="https://blog.ytso.com/category/tech/pnotes" rel="category tag">编程笔记</a>                                                            </div>
                        </div>
                        
                                                <div class="entry-content text-indent text-justify">
                            <p>	在前面的一篇文章中，我详细的分析了滑动验证码的实现原理。在本文中，我们在通过实现滑动验证码的案例和代码进一步加深理解。</p>
<p>	我们先来看一下最终的实现效果：</p>
<p>	<noscript><img decoding="async" alt="html5实现滑动验证码" src="http://img.bbs.csdn.net/upload/201703/12/1489306602_365510.png" style="width: 357px;height: 140px" /></noscript><img decoding="async" alt="html5实现滑动验证码" class="j-lazy" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png" data-original="http://img.bbs.csdn.net/upload/201703/12/1489306602_365510.png" style="width: 357px;height: 140px" /></p>
<h2>
	滑动验证码实现过程<br />
</h2>
<ol>
<li>
		先实现一个div，内容便是&ldquo;拖动滑块验证&rdquo;，设置其不可框选。背景为灰色。
	</li>
<li>
		在编写一个div，宽为滑块的宽度。背景为向右的箭头，定位在滑块框的左侧。
	</li>
<li>
		给左侧的滑块添加移动事件。mousemove、mousedown、mouseup、selectstart4个事件。
	</li>
<li>
		在移动过程中，填充左侧移动宽度的背景颜色。可以用一个div来实现，同样的定位到滑动框上。
	</li>
<li>
		滑动完成后，将滑块定位到最右侧，并改变背景颜色为成功。
	</li>
<li>
		移动未完成，滑块则止为初始位置。
	</li>
</ol>
<h2>
	滑动验证码实现代码<br />
</h2>
<pre class="brush:xml;">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;：HTML5实现滑动验证码&lt;/title&gt;
&lt;meta charset=&quot;utf-8&quot;/&gt;
&lt;type=&quot;text/css&quot;&gt;
#drag{&nbsp;
&nbsp; &nbsp; position: relative;
&nbsp; &nbsp; background-color: #e8e8e8;
&nbsp; &nbsp; width: 300px;
&nbsp; &nbsp; height: 34px;
&nbsp; &nbsp; line-height: 34px;
&nbsp; &nbsp; text-align: center;
}
#drag .handler{
&nbsp; &nbsp; position: absolute;
&nbsp; &nbsp; top: 0px;
&nbsp; &nbsp; left: 0px;
&nbsp; &nbsp; width: 40px;
&nbsp; &nbsp; height: 32px;
&nbsp; &nbsp; border: 1px solid #ccc;
&nbsp; &nbsp; cursor: move;
}
.handler_bg{
&nbsp; &nbsp; background: #fff url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmP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Zyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDphNWEzMWNhMC1hYmViLTQxNWEtYTEwZS04Y2U5NzRlN2Q4YTEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+k+sHwwAAASZJREFUeNpi/P//PwMyKD8uZw+kUoDYEYgloMIvgHg/EM/ptHx0EFk9I8wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==&quot;) no-repeat center;
}
#drag .drag_bg{
&nbsp; &nbsp; background-color: #7ac23c;
&nbsp; &nbsp; height: 34px;
&nbsp; &nbsp; width: 0px;
}
#drag .drag_text{
&nbsp; &nbsp; position: absolute;
&nbsp; &nbsp; top: 0px;
&nbsp; &nbsp; width: 300px;
&nbsp; &nbsp; -moz-user-select: none;
&nbsp; &nbsp; -webkit-user-select: none;
&nbsp; &nbsp; user-select: none;
&nbsp; &nbsp; -o-user-select:none;
&nbsp; &nbsp; -ms-user-select:none;&nbsp;
}
&lt;/style&gt;
&lt;script src=&quot;js/jquery-1.7.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
//本文作者：，www.xttblog.com
&nbsp;&nbsp; &nbsp;(function($){
&nbsp; &nbsp; $.fn.drag = function(options){
&nbsp; &nbsp; &nbsp; &nbsp; var x, drag = this, isMove = false, defaults = {
&nbsp; &nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; &nbsp; var options = $.extend(defaults, options);
&nbsp; &nbsp; &nbsp; &nbsp; //添加背景，文字，滑块
&nbsp; &nbsp; &nbsp; &nbsp; var html = &#039;&lt;div class=&quot;drag_bg&quot;&gt;&lt;/div&gt;&#039;+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&lt;div class=&quot;drag_text&quot; onselectstart=&quot;return false;&quot; unselectable=&quot;on&quot;&gt;拖动滑块验证&lt;/div&gt;&#039;+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&lt;div class=&quot;handler handler_bg&quot;&gt;&lt;/div&gt;&#039;;
&nbsp; &nbsp; &nbsp; &nbsp; this.append(html);
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; var handler = drag.find(&#039;.handler&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; var drag_bg = drag.find(&#039;.drag_bg&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; var text = drag.find(&#039;.drag_text&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; var maxWidth = drag.width() - handler.width(); &nbsp;//能滑动的最大间距
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; //鼠标按下时候的x轴的位置
&nbsp; &nbsp; &nbsp; &nbsp; handler.mousedown(function(e){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isMove = true;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = e.pageX - parseInt(handler.css(&#039;left&#039;), 10);
&nbsp; &nbsp; &nbsp; &nbsp; });
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; //鼠标指针在上下文移动时，移动距离大于0小于最大间距，滑块x轴位置等于鼠标移动距离
&nbsp; &nbsp; &nbsp; &nbsp; $(document).mousemove(function(e){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var _x = e.pageX - x;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isMove){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(_x &gt; 0 &amp;&amp; _x &lt;= maxWidth){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.css({&#039;left&#039;: _x});
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drag_bg.css({&#039;width&#039;: _x});
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else if(_x &gt; maxWidth){ &nbsp;//鼠标指针移动距离达到最大时清空事件
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dragOk();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; }).mouseup(function(e){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isMove = false;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var _x = e.pageX - x;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(_x &lt; maxWidth){ //鼠标松开时，如果没有达到最大距离位置，滑块就返回初始位置
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.css({&#039;left&#039;: 0});
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drag_bg.css({&#039;width&#039;: 0});
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; //清空事件
&nbsp; &nbsp; &nbsp; &nbsp; function dragOk(){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.removeClass(&#039;handler_bg&#039;).addClass(&#039;handler_ok_bg&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.text(&#039;验证通过&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drag.css({&#039;color&#039;: &#039;#fff&#039;});
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.unbind(&#039;mousedown&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(document).unbind(&#039;mousemove&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(document).unbind(&#039;mouseup&#039;);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; };
})(jQuery);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;drag&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(&#039;#drag&#039;).drag();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>	怎么样，看起来，很简单吧。我这里使用了一些HTML5和CSS3的一些特性。大家在修改一下兼容性，做一些风险控制，就可以应用到实际的项目中了。</p>
<p><noscript><img decoding="async" src="" alt="HTML5实现滑动验证码"/></noscript><img decoding="async" class="j-lazy" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png" data-original="" alt="HTML5实现滑动验证码"/></p>
<p>： &raquo; HTML5实现滑动验证码</p>
<p><script>    btw = new BTWPlugin();    btw.init({        id: "codedq-container",        blogId: "19659-1579686249813-193",        name: "",        qrcode: "https://gitee.com/xmtblog/img/raw/master/blog2weixin.jpg",        keyword: "996",    });</script></p>
<div class="entry-readmore"><div class="entry-readmore-btn"></div></div>                                                        <div class="entry-copyright"><p>原创文章，作者：奋斗，如若转载，请注明出处：https://blog.ytso.com/tech/aiops/251189.html</p></div>                        </div>

                        <div class="entry-tag"><a href="https://blog.ytso.com/tag/app" rel="tag">App</a><a href="https://blog.ytso.com/tag/css" rel="tag">CSS</a><a href="https://blog.ytso.com/tag/go" rel="tag">go</a><a href="https://blog.ytso.com/tag/html" rel="tag">html</a><a href="https://blog.ytso.com/tag/https" rel="tag">https</a><a href="https://blog.ytso.com/tag/javascript" rel="tag">JavaScript</a><a href="https://blog.ytso.com/tag/qt" rel="tag">Qt</a><a href="https://blog.ytso.com/tag/uml" rel="tag">UML</a><a href="https://blog.ytso.com/tag/web" rel="tag">Web</a></div>
                        <div class="entry-action">
                            <div class="btn-zan" data-id="251189"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-thumb-up-fill"></use></svg></i> 赞 <span class="entry-action-num">(0)</span></div>
                                                    </div>

                        <div class="entry-bar">
                            <div class="entry-bar-inner">
                                                                <div class="entry-bar-info entry-bar-info2">
                                    <div class="info-item meta">
                                                                                    <a class="meta-item j-heart" href="javascript:;" data-id="251189"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-star"></use></svg></i> <span class="data">0</span></a>                                        <a class="meta-item" href="#comments"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-comment"></use></svg></i> <span class="data">0</span></a>                                                                            </div>
                                    <div class="info-item share">
                                                                                    <a class="meta-item mobile j-mobile-share" href="javascript:;" data-id="251189" data-qrcode="https://blog.ytso.com/tech/aiops/251189.html">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-share"></use></svg></i> 生成海报                                            </a>
                                                                                    <a class="meta-item wechat" data-share="wechat" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-wechat"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item weibo" data-share="weibo" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-weibo"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qq" data-share="qq" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qq"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qzone" data-share="qzone" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qzone"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item douban" data-share="douban" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-douban"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item linkedin" data-share="linkedin" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-linkedin"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item facebook" data-share="facebook" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-facebook"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item twitter" data-share="twitter" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-twitter"></use></svg></i>                                            </a>
                                                                            </div>
                                    <div class="info-item act">
                                        <a href="javascript:;" id="j-reading"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-article"></use></svg></i></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                                            <div class="entry-page">
        <error>
    <code>wp_die</code>
    <title><![CDATA[WordPress &amp;rsaquo; Error]]></title>
    <message><![CDATA[&lt;h1&gt;Error establishing a Redis connection&lt;/h1&gt;
&lt;p&gt;To disable Redis, delete the &lt;code&gt;object-cache.php&lt;/code&gt; file in the &lt;code&gt;/wp-content/&lt;/code&gt; directory.&lt;/p&gt;
]]></message>
    <data>
        <status>500</status>
    </data>
</error>
<!--
Performance optimized by Redis Object Cache. Learn more: https://wprediscache.com

Retrieved 1787 objects (265 KB) from Redis using Predis (v2.4.0).
-->
