13 Star 166 Fork 25

理想三旬 / sliderVerify

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

滑块验证

没错,闲暇时光玩玩小东西,此插件仅提供学习交流

使用截图

未拖动的图片 拖动完成的图片

快速上手

获得 layui 后,将其完整地部署到你的项目目录(或静态资源服务器),你只需要引入下述一个文件:

./sliderVerify/sliderVerify.js

入门案例:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<meta name="renderer" content="webkit">
	  	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	  	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="layui/css/layui.css" />
		</head>
		<body>
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">输入框</label>
					<div class="layui-input-block">
						<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">滑动验证</label>
					<div class="layui-input-block">
						<div id="slider"></div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
<script src="../layui/layui.js"></script>
<script>
		//一般直接写在一个js文件中
		layui.config({
			base: 'dist/sliderVerify/'
		}).use(['sliderVerify', 'jquery', 'form'], function() {
			var sliderVerify = layui.sliderVerify,
				form = layui.form;
			var slider = sliderVerify.render({
				elem: '#slider',
				onOk: function(){//当验证通过回调
					layer.msg("滑块验证通过");
				}
			})
			//监听提交
			form.on('submit(formDemo)', function(data) {
				if(slider.isOk()){//用于表单验证是否已经滑动成功
					layer.msg(JSON.stringify(data.field));
				}else{
					layer.msg("请先通过滑块验证");
				}
				return false;
			});
			
		})
</script> 
</body>
</html>

如果你想按照自己的风格定义样式你可以这样:

	var slider = sliderVerify.render({
		elem: '#slider',
		isAutoVerify:false,//关闭自动验证
		bg : 'layui-bg-red',//自定义背景样式名
		text : '滑动',
		onOk: function(){//当验证通过回调
			layer.msg("滑块验证通过");
		}
	})
MIT License Copyright (c) 2019 理想三旬 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于 layui模块化 sliderVerify - 滑块验证 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/jishudaquan/sliderValidate.git
git@gitee.com:jishudaquan/sliderValidate.git
jishudaquan
sliderValidate
sliderVerify
master

搜索帮助