jq实现图片拖动滑块验证码

本文介绍如何利用jQuery创建一个图片拖动滑块验证码功能,包括html布局、css样式和js交互逻辑,旨在增强网站安全性。
摘要由CSDN通过智能技术生成

创建项目如下:
在这里插入图片描述
index.html:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>拖动滑块图片拼图验证码插件</title>
	<link href="https://cdn.bootcss.com/font-awesome/5.7.2/css/all.min.css" rel="stylesheet">
	<link href="slider/slider.css" rel="stylesheet"/>
	<style>
		.slidercaptcha {
			margin: 0 auto;
			width: 314px;
			height: 286px;
			border-radius: 4px;
			box-shadow: 0 0 10px rgba(0, 0, 0, 0.125);
			margin-top: 40px;
		}
		 
		.slidercaptcha .card-body {
			padding: 1rem;
		}
		 
		.slidercaptcha canvas:first-child {
			border-radius: 4px;
			border: 1px solid #e6e8eb;
		}
		 
		.slidercaptcha.card .card-header {
			background-image: none;
			background-color: rgba(0, 0, 0, 0.03);
		}
		 
		.refreshIcon {
			top: -54px;
		}
	</style>
</head>
<body>
	<div class="container-fluid">
		<div class="form-row">
			<div class="col-12">
				<div class="slidercaptcha card">
					<div class="card-header">
						<span>请完成安全验证</span>
					</div>
					<div class="card-body"><div id="captcha"></div></div>
				</div>
			</div>
		</div>
	</div>
	<script src="jquery.min.js" type="text/javascript"></script>
	<script src="slider/slider.js"></script>
	<script>
		$('#captcha').sliderCaptcha({
			repeatIcon: 'fa fa-redo',
			setSrc:'./imager3.png',
			onSuccess: function () {
	 
				alert('验证通过!');
			}
		});
	</script>
</body>
</html>

slider.css:

body {
  overflow-x: hidden;
}
 
.block {
  position: absolute;
  left: 0;
  top: 0;
}
 
.sliderContainer {
  position: relative;
  text-align: center;
  line-height: 40px;
  background: #f7f9fa;
  color: #45494c;
  border-radius: 2px;
}
 
.sliderbg {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  background-color: #f7f9fa;
  height: 40px;
  border-radius: 2px;
  border: 1px solid #e6e8eb;
}
 
.sliderContainer_active .slider {
  top: -1px;
  border: 1px solid #1991FA;
}
 
.sliderContainer_active .sliderMask {
  border-width: 1px 0 1px 1px;
}
 
.sliderContainer_success .slider {
  top: -1px;
  border: 1px solid #52CCBA;
  background-color: #52CCBA !important;
}
 
.sliderContainer_success .sliderMask {
  border: 1px solid #52CCBA;
  border-width: 1px 0 1px 1px;
  background-color: #D2F4EF;
}
 
.sliderContainer_success .sliderIcon:before {
  content: "\f00c";
}
 
.sliderContainer_fail .slider {
  top: -1px;
  border: 1px solid #f57a7a;
  background-color: #f57a7a !important;
}
 
.sliderContainer_fail .sliderMask {
  border: 1px solid #f57a7a;
  background-color: #fce1e1;
  border-width: 1px 0 1px 1px;
}
 
.sliderContainer_fail .sliderIcon:before {
  content: "\f00d";
}
.sliderContainer_active .sliderText, .sliderContainer_success .sliderText, .
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值