作者的话:
基于patternLock插件实现九宫格登陆校验功能。其亮点在于摒弃传统校验方式同时融合产品文化。同上一篇文章一样,本次实现功能剥离至本人15年毕设项目《ReBook》。下面介绍主要思路,详情请戳后面源码链接。
效果图:
左侧:九宫格滑动区域,右侧:登陆、提示区域
根据提示点击滑动,依次连接“借书图标”-“换书图标”-“购书图标”(以下简称“借换购”)即得结果:
开发步骤:
1. 引入相关插件文件:
主要有patternLock.js/patternLock.css。此外,本例还使用到了bootstrap、jquery相关文件。
2. 制作个性化的九宫格图:
本图将品牌REBOOK字母融入其中,同时包含了网站三大特色业务LOGO(借换购)。在此我只做了一张大图,在css中使用background-position定位。当然你也可以分解成9张小图来实现。
3. 实现登陆窗口
form表单input实现之类的大家都会,只是美与丑的差别,此处省略。
4. 解锁原理
同传统随机数字校验方式相同,我们在看到扭曲、模糊等花样作死的数字(或字母、文字)后,钛合金双眼识别成功后输入对应数字即校验成功。同理,我们将patternLock九宫格的九个区域类比成1-9这九个数字,当你依次点击滑动连接1-5-9对应区域,则意味着得到的匹配字串即为“159”,再将其与随机生成的标准答案字串对比即得结果。 1 2 3 4 5 6 7 8 9对应的代码如下:// 正确答案串var rightAnswer = "";// 初始化九宫格var lock = new PatternLock("#patternContainer");lock.checkForPattern(rightAnswer,function(){// 校验成功,激活登陆按钮 $("#login").attr("disabled",false); $("#login").removeClass("buttonDis"); //alert("验证成功");},function(){ lert("连错了,再试一次"); lock.reset();}); 此时,我们描绘的只是一个裸着的patternLock,那待我们给九个娃娃穿上漂亮的CSS图标之后是不是就大功告成了呢?
5. 前方高能
我们设想一次验证过程,假如本次后台生成的标准字串值为“589”。那么,我们需要给“5”娃穿上“借书图标”、“8”娃穿上“换书图标”、“9”娃穿上“购书图标”,其他娃娃们就随便穿了。因为对于用户们来说,不论后台生成的标答是什么,他们的标答永远都是依次连接“借换购”就能验证成功。所以我们,在九宫格区域映射对应样式过程需要划分成两部分,一部分专属标答随机映射,一部分剩余部分的随意映射,实现每次用户进入看到的展示效果不同。此外,还有个问题。如果真的太随机了对于用户在电脑上连接确实会有一定的难度,用户体验下降。于是本例做了小小的限制,将标答的产生范围从3X3缩小到了2X2(即5689对于区域)。
6.Demo源码
附录:
-
patternLock官网

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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),

WebStorm Mac version
Useful JavaScript development tools
