js登录滑动验证的实现(不滑动无法登陆)


Posted in Javascript onJanuary 03, 2018

js的判断这里是根据滑块的位置进行判断,应该是用一个flag判断

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
 String basePath = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录</title>
<link href="<%=basePath%>/res/css/bootstrap.min14ed.css?v=3.3.6" rel="external nofollow" 
 rel="stylesheet">
<link href="<%=basePath%>/res/css/font-awesome.min93e3.css?v=4.4.0" rel="external nofollow" 
 rel="stylesheet">
<link href="<%=basePath%>/res/css/animate.min.css" rel="external nofollow" rel="stylesheet">
<link href="<%=basePath%>/res/css/style.min862f.css?v=4.1.0" rel="external nofollow" 
 rel="stylesheet">
<!--[if lt IE 9]>
 <meta http-equiv="refresh" content="0;ie.html" />
 <![endif]-->
<script>
 if (window.top !== window.self) {
 window.top.location = window.location;
 }
</script>
<style>
* {
 margin: 0;
 padding: 0;
}
body {
 font: 12px/1.125 Microsoft YaHei;
 background: #fff;
}
ul, li {
 list-style: none;
}
a {
 text-decoration: none;
}
.ani {
 transition: all .3s;
}
.wrap {
 width: 300px;
 height:;
 text-align: center;
 margin: 150px auto;
}
.inner {
 padding: 15px;
}
.clearfix {
 overflow: hidden;
 _zoom: 1;
}
.none {
 display: none;
}
#slider {
 position: relative;
 background-color: #e8e8e8;
 width: 300px;
 height: 34px;
 line-height: 34px;
 text-align: center;
}
#slider .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/9hAAAAGXRFWHRTb2Z0d2FyZQBBZ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k00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==")
 no-repeat center;
}
#slider .drag_bg {
 background-color: #7ac23c;
 height: 34px;
 width: 0px;
}
#slider .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;
}
.unselect {
 -moz-user-select: none;
 -webkit-user-select: none;
 -ms-user-select: none;
}
.slide_ok {
 color: #fff;
}
</style>
</head>
<style>
.btn-primary {
 background-color: #0000FF;
}
.btn-primary:hover {
 background-color: #0000FF;
}
.btn-primary {
 background-color: #0000FF;
 border-color: #0000FF;
}
</style>
<body class="gray-bg">
 <div class="middle-box text-center loginscreen animated fadeInDown">
 <div>
  <h3 style="margin-top: 100px;">欢迎登录</h3>
  <form class="m-t" role="form" action="<%=basePath%>/login"
  method="POST" onsubmit="return login();">
  <div class="form-group">
   <input name="username" id="username" type="text"
   class="form-control" placeholder="用户名" required="">
  </div>
  <div class="form-group">
   <input type="password" name="password" id="password"
   class="form-control" placeholder="密码" required="">
  </div>
  
  <div class="wrap" style="margin: 10px auto 10px">
   <div id="slider">
   <div class="drag_bg"></div>
   <div class="drag_text" onselectstart="return false;"
    unselectable="on">拖动滑块验证</div>
   <div class="handler handler_bg"></div>
   </div>
  </div>
  <input type="hidden" name="${_csrf.parameterName}"
   value="${_csrf.token}">
  <button type="submit" style="background-color: #0000FF;" class="btn btn-primary block full-width m-b">登
   录</button>
  <%
   if (request.getParameter("error") != null) {
  %>
  <span id="" style="color: red;">账号或者密码错误!</span>
  <%
   }
  %>
  <%
   if (request.getParameter("logout") != null) {
  %>
  <span>已经安全退出!</span>
  <%
   }
  %>
  <p class="text-muted text-center">
   <a href="login.html#" rel="external nofollow" ><small>忘记密码了?</small></a> | <a
   href="<%=basePath%>/register" rel="external nofollow" >注册一个新账号</a>
  </p>
  </form>
 </div>
 </div>
 <script src="<%=basePath%>/res/js/jquery.min.js?v=2.1.4"></script>
 <script src="<%=basePath%>/res/js/bootstrap.min.js?v=3.3.6"></script>
</body>
<script type="text/javascript"
 src="<%=basePath%>/res/js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/res/js/jquery.md5.js"></script>
<script type="text/javascript">
 $(function() {
 $('#username').val();
 });
 function login() {
 if($(".drag_bg").width()<260){
  return false;
 }
 var password = $('#password').val();
 password = $.md5(password);
 console.log(password);
 $('#password').val(password);
 return true;
 }
</script>
<script>
 (function(window, document, undefined) {
 var dog = {//声明一个命名空间,或者称为对象
  $ : function(id) {
  return document.querySelector(id);
  },
  on : function(el, type, handler) {
  el.addEventListener(type, handler, false);
  },
  off : function(el, type, handler) {
  el.removeEventListener(type, handler, false);
  }
 };
 //封装一个滑块类
 function Slider() {
  var args = arguments[0];
  for ( var i in args) {
  this[i] = args[i]; //一种快捷的初始化配置
  }
  //直接进行函数初始化,表示生成实例对象就会执行初始化
  this.init();
}
Slider.prototype = {
  constructor : Slider,
  init : function() {
  this.getDom();
  this.dragBar(this.handler);
  },
  getDom : function() {
  this.slider = dog.$('#' + this.id);
  this.handler = dog.$('.handler');
  this.bg = dog.$('.drag_bg');
  },
  dragBar : function(handler) {
  var that = this, startX = 0, lastX = 0, doc = document, width = this.slider.offsetWidth, max = width
   - handler.offsetWidth, drag = {
   down : function(e) {
   var e = e || window.event;
   that.slider.classList.add('unselect');
   startX = e.clientX - handler.offsetLeft;
   console.log('startX: ' + startX + ' px');
   dog.on(doc, 'mousemove', drag.move);
   dog.on(doc, 'mouseup', drag.up);
   return false;
   },
   move : function(e) {
   var e = e || window.event;
   lastX = e.clientX - startX;
   lastX = Math.max(0, Math.min(max, lastX)); //这一步表示距离大于0小于max,巧妙写法
   console.log('lastX: ' + lastX + ' px');
   if (lastX >= max) {
    handler.classList.add('handler_ok_bg');
    that.slider.classList.add('slide_ok');
    dog.off(handler, 'mousedown', drag.down);
    drag.up();
   }
   that.bg.style.width = lastX + 'px';
   handler.style.left = lastX + 'px';
   },
   up : function(e) {
   var e = e || window.event;
   that.slider.classList.remove('unselect');
   if (lastX < width) {
    that.bg.classList.add('ani');
    handler.classList.add('ani');
    that.bg.style.width = 0;
    handler.style.left = 0;
    setTimeout(function() {
    that.bg.classList.remove('ani');
    handler.classList.remove('ani');
    }, 300);
   }
   dog.off(doc, 'mousemove', drag.move);
   dog.off(doc, 'mouseup', drag.up);
   }
  };
  dog.on(handler, 'mousedown', drag.down);
  }
 };
 window.S = window.Slider = Slider;
 })(window, document);
 var defaults = {
 id : 'slider'
 };
 new S(defaults);
</script>
</html>

以上这篇js登录滑动验证的实现(不滑动无法登陆)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
使用jQuery UI的tooltip函数修饰title属性的气泡悬浮框
Jun 24 Javascript
动态加载iframe时get请求传递中文参数乱码解决方法
May 07 Javascript
使用jQuery的attr方法来修改onclick值
Jul 07 Javascript
javascript图片预加载完整实例
Dec 10 Javascript
JavaScript遍历求解数独问题的主要思路小结
Jun 12 Javascript
浅谈移动端之js touch事件 手势滑动事件
Nov 07 Javascript
lhgcalendar时间插件限制只能选择三个月的实现方法
Jul 03 Javascript
关于JavaScript语句后面的分号问题
Dec 07 Javascript
使用async await 封装 axios的方法
Jul 09 Javascript
JavaScript实现五子棋游戏的方法详解
Jul 08 Javascript
改变layer confirm弹窗按钮的颜色方法
Sep 12 Javascript
vue中axios封装使用的完整教程
Mar 03 Vue.js
Angular实现下拉框模糊查询功能示例
Jan 03 #Javascript
Node使用Sequlize连接Mysql报错:Access denied for user ‘xxx’@‘localhost’
Jan 03 #Javascript
angularjs实现分页和搜索功能
Jan 03 #Javascript
vue引入ueditor及node后台配置详解
Jan 03 #Javascript
Node.js搭建小程序后台服务
Jan 03 #Javascript
基于js文件加载优化(详解)
Jan 03 #Javascript
jQuery 实现左右两侧菜单添加、移除功能
Jan 02 #jQuery
You might like
php流量统计功能的实现代码
2012/09/29 PHP
php魔术方法功能与用法实例分析
2016/10/19 PHP
thinkPHP框架可添加js事件的分页类customPage.class.php完整实例
2017/03/16 PHP
jQuery ajax+PHP实现的级联下拉列表框功能示例
2019/02/12 PHP
javascript学习网址备忘
2007/05/29 Javascript
jQuery调用RESTful WCF示例代码(GET方法/POST方法)
2014/01/26 Javascript
javascript学习笔记之10个原生技巧
2014/05/21 Javascript
form.submit()不能提交表单的错误原因及解决方法
2014/10/13 Javascript
jQuery搜索子元素的方法
2015/02/10 Javascript
封装好的javascript前端分页插件pagination
2016/01/04 Javascript
基于Jquery插件实现跨域异步上传文件功能
2016/04/26 Javascript
AngularJs基于角色的前端访问控制的实现
2016/11/07 Javascript
AngularJS中的缓存使用
2017/01/11 Javascript
vue拖拽排序插件vuedraggable使用方法详解
2020/08/21 Javascript
ES6知识点整理之函数对象参数默认值及其解构应用示例
2019/04/17 Javascript
详解vue 路由跳转四种方式 (带参数)
2019/04/28 Javascript
浅谈vue中组件绑定事件时是否加.native
2019/11/09 Javascript
vue学习笔记之slot插槽基本用法实例分析
2020/02/01 Javascript
使用TS来编写express服务器的方法步骤
2020/10/29 Javascript
详解Python命令行解析工具Argparse
2016/04/20 Python
基于循环神经网络(RNN)的古诗生成器
2018/03/26 Python
Python(Django)项目与Apache的管理交互的方法
2018/05/16 Python
Python高级编程之继承问题详解(super与mro)
2019/11/19 Python
Python函数的返回值、匿名函数lambda、filter函数、map函数、reduce函数用法实例分析
2019/12/26 Python
基于python tkinter的点名小程序功能的实例代码
2020/08/22 Python
汽车销售顾问求职自荐信
2014/01/01 职场文书
《青海高原一株柳》教学反思
2014/04/25 职场文书
小学生倡议书范文
2014/05/13 职场文书
校园演讲稿汇总
2014/05/21 职场文书
三八妇女节超市活动方案
2014/08/18 职场文书
中班教师个人总结
2015/02/05 职场文书
2015年母亲节活动总结
2015/02/10 职场文书
单位推荐信范文
2015/03/27 职场文书
小学生红领巾广播稿
2015/08/19 职场文书
MySQL update set 和 and的区别
2021/05/08 MySQL
mysql 如何获取两个集合的交集/差集/并集
2021/06/08 MySQL