The content this article brings to you is about js implementation of sliding slider verification (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="pintu.css" type="text/css"> </head> <body> <div> <div> <!--<img src="/static/imghwm/default1.png" data-src="image/1.png" class="lazy" alt="js implements sliding slider verification (with code)" >--> <div></div> <div></div> </div> <div> <span></span> <span>拖动滑块</span> </div> </div> <script src="jquery.js"></script> <script src="pintu.js"></script> </body> </html>
css: .box { width: 300px; background-color: palevioletred; padding: 20px; background-color: #fff; box-shadow: 2px 2px 8px 0 rgba(0, 0, 0, 0.4); } .imgBox img { width: 100%; } .imgBox { position: relative; width: 300px; overflow: hidden; box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.4); } .verify { position: absolute; left: 10px; width: 38px; height: 38px; top: 50%; border-radius: 5px; background-repeat: no-repeat; background-attachment: scroll; background-size: 300px; box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4), 0 0 10px 0 rgba(90, 90, 90, 0.4); z-index: 1; } .verified { position: absolute; width: 38px; height: 38px; top: 50%; right: 10px; border-radius: 5px; background-color: rgba(0, 0, 0, 0.1); box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4) inset; } .handle { display: flex; align-items: center; position: relative; height: 30px; border-radius: 20px; margin: 20px 0; padding: 4px 0 4px 70px; box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2) inset; background: #f5f5f5; user-select: none; } .swiper { position: absolute; top: -7px; left: 0px; width: 48px; height: 48px; border-radius: 50%; background-color: pink; box-shadow: 2px 2px 6px 0 rgba(0, 0, 0, 0.2); z-index: 2; } .text { color: #aaa; position: relative; z-index: 1; width: 100%; border-radius: 8px; padding-left: 20px; margin-left: -30px; background: -webkit-gradient(linear, left top, right top, color-stop(0, #f1f1f1), color-stop(1, #f5f5f5)); transition: opacity 0.5s ease-in-out; -webkit-animation: slidetounlock 2s infinite; } @keyframes slidetounlock { 0% { background-position: -100px 0 } 50%{ background-position: 0px 0 } 100% { background-position: 100px 0 } }
js: var box = $('.box'), imgBox = $('.imgBox'), handle = $('.handle') swiper = $('.swiper'), text = $('.text'), verify = $('.verify'), verified = $('.verified') $(function () { // 随机添加背景图 refreshImg() window.onload = start() }) function start() { var verImg = $('.verImg')[0]; if (verImg) { verImg.onload = function () { //获取图片的高度 var imgH = this.clientHeight; //随机生成坐标(图片框固定宽度为300px 高度不定) var verX = 150 * (1 + Math.random()) - 38, verY = imgH / 4 + Math.random() * imgH / 2; //用户滑动函数 fnDown(verX, verY); } } } function fnDown(verX, verY) { swiper.mousedown(function () { e=event || window.event e.stopPropagation()//阻止冒泡行为(让子元素与父元素的响应分离) //30为模块的宽度 verify.css({ display: 'block', top: `${verY}px`, 'background-position': `-${verX}px -${verY}px` }) verified.css({display: 'block', left: `${verX}px`, top: `${verY}px`}) // 获取鼠标到按钮的距离 var disX = e.clientX - $(this).offset().left, disY = e.clientY - $(this).offset().top; text.css('opacity', '0'); //防止重复绑定多次触发 box.unbind('mousemove'); box.unbind('mouseup'); //移动 box.bind('mousemove', function () { e = event || window.event; fnMove(e, disX, disY); }) //释放 box.bind('mouseup', function () { var stopL = verify.offset().left - 28; //误差在2px以内则算验证成功 if (Math.abs(stopL - verX) > 2) { alert('验证失败'); } else { alert('验证成功'); } //解除绑定,并将滑块模块归位 box.unbind('mousemove'); swiper.css('left', '0px'); verify.css('left', '10px'); text.css('opacity', '1') box.unbind('mouseup'); }) }) } function fnMove(e, posX, posY) { // 这里的e是以鼠标为参考 var l = e.clientX - posX - $(handle).offset().left, winW = $(handle).width() + 29 // 限制拖动范围只能在handle中 if (l winW) { l = winW } swiper.css('left', `${l}px`) verify.css('left', `${l + 10}px`) } function refreshImg() { verify.hide() verified.hide() var verImg = $('.verImg') if (verImg.length) { verImg.attr('src', `image/1.png`) } else { imgBox.prepend(`<img src="/static/imghwm/default1.png" data-src="image/1.png" class="lazy" alt="js implements sliding slider verification (with code)" >`) } verify.css('background-image', `url('image/1.png')`) }
Related recommendations:
How to implement picture sliding verification code
js and canvas implementation Sliding puzzle verification code function
Implements dragging slider verification function based on JS component
js login sliding verification accomplish
The above is the detailed content of js implements sliding slider verification (with code). For more information, please follow other related articles on the PHP Chinese website!

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.