This article brings you relevant knowledge about JavaScript. It mainly introduces how to achieve the novice guidance effect through simple CSS and JS. Interested friends can take a look below. Well, I hope it helps everyone.
The beginning of nonsense: through some simple CSS and JS to achieve the novice guidance effect
1. To achieve the effect
2. To achieve
The implementation is actually very simple, mask The version is to tile a whole screen div, set the background color to transparent transparent, and then set outline to semi-transparent and wide enough. Then create an arrow and warning label in the same way.
1. Usage
let maskIntroduceManage = new MaskIntroduceManage([ new MaskIntroduceItem('one','人生若只如初见'), new MaskIntroduceItem('two','何事秋风悲画扇'), new MaskIntroduceItem('five','等闲却变故人心'), new MaskIntroduceItem('six','骊山语罢清宵半'), new MaskIntroduceItem('four','却道故人心易变'), new MaskIntroduceItem('finally','谢谢大家支持!') ]) maskIntroduceManage.benginIntroduce()
2. HTML
nbsp;html> <meta> <style> *{ padding: 0; margin: 0; } .content { padding: 0; display: flex; flex-direction: row; justify-content: space-between; align-items: center; width: 100%; } span { width: 60px; height: 60px; line-height: 60px; margin-left: 40px; margin-top: 140px; margin-bottom: 0px; text-align: center; display: block; background-color: antiquewhite; } .finally { width: 100px; height: 100px; background-color: cornsilk; border-radius: 50%; line-height: 100px; text-align: center; margin-top: 30px; margin-left: auto; margin-right: auto; } span:nth-of-type(1){ margin-top: 30px; } span:nth-of-type(2){ margin-top: 70px; } span:nth-of-type(3){ margin-top: 160px; } span:nth-of-type(4){ margin-top: 160px; } span:nth-of-type(5){ margin-top: 70px; } span:nth-of-type(6){ margin-top: 30px; } </style> <div> <span>纳</span> <span>兰</span> <span>容</span> <span>若</span> <span>作</span> <span>词</span> </div> <div> 谢谢 </div> <script></script> <script> let maskIntroduceManage = new MaskIntroduceManage([ new MaskIntroduceItem('one','人生若只如初见'), new MaskIntroduceItem('two','何事秋风悲画扇'), new MaskIntroduceItem('five','等闲却变故人心'), new MaskIntroduceItem('six','骊山语罢清宵半'), new MaskIntroduceItem('four','却道故人心易变'), new MaskIntroduceItem('finally','谢谢大家支持!') ]) maskIntroduceManage.benginIntroduce() </script>
3.JS
// 单元信息model class MaskIntroduceItem { // 需要引导的dom的ID id // 需要引导的dom功能描述 warming constructor(id,warming){ this.id = id this.warming = warming } } // 遮罩操作类 class MaskIntroduceManage { // 消息展示类集合 maskIntroduceItems // 遮罩层 el // 遮罩层提示框 warmingEl // 指引肩头 guidanceEl // 展示的第几个 currentShowIndex = 0 // 记录window事件 windowEvent = null constructor(maskIntroduceItems){ this.maskIntroduceItems = maskIntroduceItems } // 添加消息展示类 addIntroduceItem(introduceItem){ this.maskIntroduceItems.push(introduceItem) } // body增加遮罩 addMaskToBody(){ //添加遮罩框 this.el = document.createElement('div') this.el.style.cssText = 'position: fixed;background: transparent;outline:rgba(0, 0, 0, 0.5) 3500px solid;' let body = document.getElementsByTagName('body')[0] body.appendChild(this.el) //添加提示框 this.warmingEl = document.createElement('div') this.warmingEl.style.cssText = 'position:fixed;width:100px;background:white;border-radius: 10px;padding: 30px;font-size: 14px;' body.appendChild(this.warmingEl) //添加指引箭头 this.guidanceEl = document.createElement('div') this.guidanceEl.style.cssText = 'position:fixed;width: 14px; height: 13px; background-color: white;clip-path: polygon(50% 0,100% 100%,0 100%);' body.appendChild(this.guidanceEl) //设置body禁止滚动 body.style.overflow = 'hidden' //保留window事件 if(window.onclick){ this.windowEvent = window.onclick } window.onclick = ()=>{ this.nextIntroduce() } } // 开始引导 benginIntroduce(){ this.addMaskToBody() this.nextIntroduce() } // 下一步 nextIntroduce(){ let maskIntroduceItem = this.maskIntroduceItems.length > 0 ? this.maskIntroduceItems[this.currentShowIndex] : null if(!maskIntroduceItem){ return } let needIntroduceEl = document.getElementById(maskIntroduceItem.id) //遮罩层的镂空位置 this.el.style.width = needIntroduceEl.offsetWidth + 'px' this.el.style.height = needIntroduceEl.offsetHeight + 'px' this.el.style.top = this.getElementPosition(needIntroduceEl).top + 'px' this.el.style.left = this.getElementPosition(needIntroduceEl).left + 'px' //设置对应倒角,但是由于背景颜色是透明的,所以,没有效果(???) //this.el.style.borderRadius = window.getComputedStyle(needIntroduceEl,null)['border-radius'] this.currentShowIndex ++ //指引箭头位置 let guidanceElLeft = this.getElementPosition(needIntroduceEl).left + needIntroduceEl.offsetWidth / 2.0 this.guidanceEl.style.top = this.getElementPosition(needIntroduceEl).top + needIntroduceEl.offsetHeight + 20 + 'px' this.guidanceEl.style.left = guidanceElLeft + 'px' //提示框的位置 this.warmingEl.style.top = this.getElementPosition(this.guidanceEl).top + this.guidanceEl.offsetHeight - 4 + 'px' let warmingElLeft = this.getElementPosition(needIntroduceEl).left - ((this.warmingEl.offsetWidth - needIntroduceEl.offsetWidth) / 2.0) if(warmingElLeft document.getElementsByTagName('body')[0].offsetWidth){ warmingElLeft = warmingElLeft - 10 - (this.warmingEl.offsetWidth - needIntroduceEl.offsetWidth) / 2.0 } this.warmingEl.style.left = warmingElLeft + 'px' this.warmingEl.innerHTML = maskIntroduceItem.warming //最后一个展示完恢复window点击事件 if(this.currentShowIndex >= this.maskIntroduceItems.length){ setTimeout(() => { //移除当前遮罩 this.el.remove() //移除当前提示框 this.warmingEl.remove() //移除箭头 this.guidanceEl.remove() //设置body可以滚动 document.getElementsByTagName('body')[0].style.overflow = 'auto' //恢复window事件 if(this.windowEvent){ window.onclick = this.windowEvent } }, 2000); } } // 获取元素在屏幕的位置 getElementPosition(element){ var top = element.offsetTop var left = element.offsetLeft var currentParent = element.offsetParent; while (currentParent !== null) { top += currentParent.offsetTop left += currentParent.offsetLeft currentParent = currentParent.offsetParent } return {top,left} } }
3. Summary and Thoughts
The implementation principle is very simple, there is not much complicated logic in it, I want to pass the current "Need to introduce" tag borderRadius to set the chamfer value of the hollow part, but the background color is transparent, so setting it will take effect but has no effect. The code is clumsy, don’t laugh at the master~
Recommended study: "JavaScript Video Tutorial"
The above is the detailed content of JS+CSS quickly realizes novice guidance effect. For more information, please follow other related articles on the PHP Chinese website!

JavaScript 不提供任何内存管理操作。相反,内存由 JavaScript VM 通过内存回收过程管理,该过程称为垃圾收集。

vscode自身是支持vue文件组件跳转到定义的,但是支持的力度是非常弱的。我们在vue-cli的配置的下,可以写很多灵活的用法,这样可以提升我们的生产效率。但是正是这些灵活的写法,导致了vscode自身提供的功能无法支持跳转到文件定义。为了兼容这些灵活的写法,提高工作效率,所以写了一个vscode支持vue文件跳转到定义的插件。

Node 19已正式发布,下面本篇文章就来带大家详解了解一下Node.js 19的 6 大特性,希望对大家有所帮助!

选择一个Node的Docker镜像看起来像是一件小事,但是镜像的大小和潜在漏洞可能会对你的CI/CD流程和安全造成重大的影响。那我们如何选择一个最好Node.js Docker镜像呢?

本篇文章给大家整理和分享几个前端文件处理相关的实用工具库,共分成6大类一一介绍给大家,希望对大家有所帮助。


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

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.

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

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.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version
