一、index.html
<!DOCTYPE html>
<html lang="zh">
<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.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!--图标样式-->
<link href="https://cdn.bootcss.com/font-awesome/5.7.2/css/all.min.css" rel="stylesheet">
<!--主要样式-->
<link href="拼图.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="https://code.jquery.com/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="longbow.slidercaptcha.js"></script>
<script>
$('#captcha').sliderCaptcha({
repeatIcon: 'fa fa-redo',
setSrc: function () {
return 'http://images.sdgxgz.com/Pic' + Math.round(Math.random() * 136) + '.jpg';
},
onSuccess: function () {
alert('验证通过!');
}
});
</script>
</body>
</html>
二、拼图.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 .sliderTex