抄自B站Up主CodingStartup起码课

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head> <body>
<div id="captcha">
<div id="handle"><span></span></div>
</div>
</body> </html> <script>
const captcha = document.querySelector('#captcha');
const handle = document.querySelector('#handle');
const button = document.querySelector('#handle span'); var moving = false; button.addEventListener('mousedown', e => {
moving = true;
});
document.body.addEventListener('mouseup', e => {
if (moving) {
const finalOffset = e.clientX - handle.getBoundingClientRect().left;
if (finalOffset >= 430 && finalOffset <= 450) {
// pass
captcha.classList.add('passed');
}
else {
// failed
captcha.style.setProperty('--move', '0px');
} moving = false;
}
});
document.body.addEventListener('mousemove', e => {
if (moving) {
const offsetLeft = handle.getBoundingClientRect().left;
const buttonWidth = button.getBoundingClientRect().width;
captcha.style.setProperty('--move', `${e.clientX - offsetLeft - buttonWidth / 2}px`);
}
}); /*
captcha.style.setProperty('--move', `${e.clientX - offsetLeft - buttonWidth / 2}px`)
*/
</script> <style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center; background-image: radial-gradient(circle farthest-corner at 10% 20%, rgba(0, 152, 155, 1) 0.1%, rgba(0, 94, 120, 1) 94.2%);
} #captcha {
--move: 20px;
--width: 400px;
--height: 260px;
--puzzle-width: 80px;
--puzzle-height: 80px; display: block;
width: var(--width);
height: var(--height); border-radius: 5px; background-image: url(https://img2.baidu.com/it/u=2444031136,1156137205&fm=26&fmt=auto&gp=0.jpg);
background-size: cover;
background-position: center;
box-shadow: 4px 4px 8px rgba(0, 0, 0, .2);
} #captcha::before,
#captcha::after {
position: absolute;
content: '';
display: block;
width: inherit;
height: inherit; background-image: inherit;
background-size: inherit;
background-position: inherit; clip-path: inset(calc((var(--height) - var(--puzzle-height)) / 2) var(--puzzle-width) calc((var(--height) - var(--puzzle-height)) / 2) calc(var(--width) - var(--puzzle-width) * 2)); } #captcha::before {
background-color: rgba(0, 0, 0, .6);
background-blend-mode: darken;
} #captcha::after {
transform: translateX(calc(var(--width) * -1 + clamp(0px,
var(--move),
calc(var(--width) + var(--puzzle-width)))));
transition: .2s all ease-in-out;
} #handle {
width: calc(var(--width) + var(--puzzle-width) * 2);
height: 25px;
border-radius: 15px;
background-color: #eee;
position: absolute;
transform: translate(calc(-1 * var(--puzzle-width) * 2), calc(var(--height) + 20px));
box-shadow: inset 0 0 10px rgba(0, 0, 0, .3);
border: solid 2px rgba(0, 0, 0, .2)
} #handle span {
display: block;
width: var(--puzzle-width);
height: inherit;
border-radius: inherit;
background-color: #fff;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .4),
0 0 4px rgba(0, 0, 0, .3);
position: absolute;
cursor: move;
transform: translateX(clamp(0px,
var(--move),
calc(var(--width) + var(--puzzle-width))));
transition: .2s all ease-in-out;
} #captcha.passed::before,
#captcha.passed::after,
#captcha.passed #handle {
opacity: 0;
} #captcha:active #handle span,#captcha:active::after{
transition:none;
}
</style>

【CSS】拼图验证练习的更多相关文章

  1. 鸿蒙第三方组件——SwipeCaptcha滑动拼图验证组件

    目录:1.组件效果展示2.Sample解析3.<鸿蒙第三方组件>系列文章合集 前言 基于安卓平台的滑动拼图验证组件SwipeCaptcha( https://github.com/mcxt ...

  2. 乱序拼图验证的识别并还原-puzzle-captcha

    一.前言 乱序拼图验证是一种较少见的验证码防御,市面上更多的是拖动滑块,被完美攻克的有不少,都在行为轨迹上下足了功夫,本文不讨论轨迹模拟范畴,就只针对拼图还原进行研究. 找一个市面比较普及的顶像乱序拼 ...

  3. C# 滑动验证码|拼图验证|SlideCaptcha

    使用背景: 关于滑动验证码的使用场所还是非常多的,如: 调取短信接口之前,和 注册请求之前 或者 频繁会调用的接口 都需要加这个拼图验证.这里先上一下效果图吧(心中无码,自然高清). 话不多说,开撸! ...

  4. 极验3.0滑动拼图验证的使用--java

    [ 前言: 在登录其他网站的时候,看到有个滑动拼图的验证觉得挺好玩的,以前做一个图片验证的小demo,现在发现很多网站都开始流行滑动拼图的验证了,今天也想自己动手来弄一个. 废话不多说,开始撸起来! ...

  5. jquery validate的漂亮css样式验证

    自己结合了在网上找的验证功能和漂亮的提示同能后做出来的验证 希望大家喜欢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...

  6. Html与CSS快速入门01-基础概念

    Web前端技术一直是自己的薄弱环节,经常为了调节一个简单的样式花费大量的时间.最近趁着在做前端部分的开发,果断把这部分知识成体系的恶补一下.内容相对都比较简单,很类似工具手册的学习,但目标是熟练掌握. ...

  7. XX宝面试题——css部分

    1.<b></b>与<strong></strong>有什么不同? 1) <b>标签是一个实体标签,它所包围的字符将被设为bold(粗体), ...

  8. 联系电话正则表达式(jquery表单验证)

    一.实现的效果图: 二.CSS样式 /*验证样式*/ .onError{ vertical-align: middle; color: #ff0000; line-height: 22px; padd ...

  9. 19.3.5日,报关于表单验证和ui-router

    今天完成的事情: (1)学习angularJS表单验证 可以验证的内容<input type="text" minlength="2" maxlength ...

随机推荐

  1. 深入刨析tomcat 之---第14篇 对应19章,使用manager管理 web应用

    writedby 张艳涛 第19章讲的是管理程序,当一个tomcat启动的时候,能通过远程浏览器能访问tomcat,启动web应用,关闭web应用,查看web应用 怎么实现的呢? 在webapp 文件 ...

  2. bootstrap table记录一下

    $(function() { // 刷新 talbe function refresh() { $("#table").bootstrapTable('refresh'); } $ ...

  3. Python语法之用户交互与基本运算符

    一.与用户交互 1.接收用户输入 python3中的input会把用户输入的所有内容都存成str类型 age = input("请输入您的年龄: ") # "内容&quo ...

  4. 走心的中级Android工程师跳槽经验分享

    这些经验是我最近四个月,从准备面试到找到合适工作的汗水和泪水,希望对你们能有帮助! define 跳槽 跳槽前要思考的问题 钱不到位怎么办 心委屈怎么办 离职前的思考 确定要走时需要做的准备 行情怎么 ...

  5. MapReduce框架原理--Shuffle机制

    Shuffle机制 Mapreduce确保每个reducer的输入都是按键排序的.系统执行排序的过程(Map方法之后,Reduce方法之前的数据处理过程)称之为Shuffle. partition分区 ...

  6. xubuntu下制作自定义的ISO文件

    by han; 1.打开命令编辑器,建立文件 # sudo su # mkdir -p /opt/custom_conf/user_custom_conf/config 2.将自定义的设置复制保存到/ ...

  7. 遗传算法 TSP(Python代码)

    该代码是本人根据B站up主侯昶曦的代码所修改的. 原代码github地址:https://github.com/Houchangxi/heuristic-algorithm/blob/master/T ...

  8. 案例分享:Qt政务标签设计器,标签排版软件定制与打印

    需求   1.标签设计器:  2.具备文字排版功能:  3.支持六种排版格式:  4.排版后可以输出打印(demo中不包含):  5.排版后可以输出标签的指定协议文本FBD格式:  6.可以调整对应标 ...

  9. Distribute SSH Pubkey to Multiple Hosts with Fabric

    Generate ssh keys on source host with ssh-keygen; Disable known_hosts prompt(optional): add "St ...

  10. PTA数据结构习题集

    https://blog.csdn.net/qq_43733499/category_8956159.html https://www.cnblogs.com/nonlinearthink/tag/% ...