抄自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. SpringCloud升级之路2020.0.x版-1.背景

    本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ Spring ...

  2. 10分钟物联网设备接入阿里云IoT平台

    前言最近尝试了一下阿里云IoT物联网平台,还是蛮强大的.在此记录一下学习过程.本教程不需要任何外围硬件,一台电脑和一根能上网的网线即可.算是一篇Hello World了.先上效果图 第一章 准备工作1 ...

  3. intouch制作历史报警查询(时间查询,筛选关键字)

    在项目中,intouch制作历史报警查询已属于标配功能,如何做出按时间以及关键字来进行综合查询,提高历史报警查询效率仍然是一个值得研究的问题,接下来参考网上文章自己总结下如何制作. 1.DTPicke ...

  4. PWA渐进式web应用

    PWA(Progressive Web App)是一种理念,使用多种技术来增强web app的功能,可以让网站的体验变得更好,能够模拟一些原生功能,比如通知推送.在移动端利用标准化框架,让网页应用呈现 ...

  5. Hadoop 3.1.1 - Yarn - 使用 FPGA

    在 Yarn 上使用 FPGA 前提 YARN 目前只支持通过 IntelFpgaOpenclPlugin 发布的 FPGA 资源 YARN NodeManager 所在的机器上必须预先安装供应商的驱 ...

  6. 开机时自动启动的AutoHotkey脚本 2019年10月09日

    ;;; 开机时自动启动的AutoHotkey脚本 2019年10月09日;; http://www.autoahk.com/archives/16600; https://www.cnblogs.co ...

  7. 离线安装zadig

    官网:https://koderover.com/ 官方给的离线安装问题有些问题,这里记录下自己离线安装的一些过程. 整体安装思路: 根据官方给出的helm安装方式以及离线安装方式结合而来. 通过官方 ...

  8. BSTestRunner增加历史执行记录展示和重试功能

    之前对于用例的失败重试,和用例的历史测试记录存储展示做了很多的描述呢,但是都是基于各个项目呢,不方便使用,为了更好的使用,我们对这里进行抽离,抽离出来一个单独的模块,集成到BSTestRunner中, ...

  9. 【LeetCode】169. 多数元素

    169. 多数元素 知识点:数组:排序:消消乐:分治: 题目描述 给定一个大小为 n 的数组,找到其中的多数元素.多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素. 你可以假设数组是非空的, ...

  10. [C++]-map和unordered_map

    转自:https://blog.csdn.net/BillCYJ/article/details/78985895 头文件不同 map: #include < map > unordere ...