function points
Before the festival, I encountered a requirement: "Newcomer Guidance Effect" guides the main functions of users who use the platform for the first time .
The specific guidance path is: click the "Add button", explain the pop-up content, guide the user to fill in the form, and finally submit the form.
The following is a screenshot of the effect ( interested brothers can implement it by themselves, I use vue
+ ElementUI
):
What we migrant workers want is efficiency. We do not produce wheels, we are all wheel porters.
Are there ready-made wheels?
Use a search engine to find solutions.
Common plugins
- vue-introjs
- driver.js
- http://bootstraptour.com/api/
- https://github.com/pulsardev/vue-tour
- https://github.com/shipshapecode/shepherd
- https://github.com/zurb/joyride
accomplish
I tried introjs and driver.js, and finally used introjs to implement, but both libraries have unsatisfactory points .
introjs
- http://jsrun.net/ERQKp/edit The new button is easy to use, but the input in the pop-up window cannot be clicked. ( It is also possible that elementUI is poisonous )
I ended up usingpointer-events: none;user-select: none;
+ state in boot to do it myself. - Does not support next callback, does not support delay control.
I finally divided the guide into two steps to implement, manually implementing the delay logic
- http://jsrun.net/ERQKp/edit The new button is easy to use, but the input in the pop-up window cannot be clicked. ( It is also possible that elementUI is poisonous )
driver.js
- When http://jsrun.net/PmQKp/edit seems to pop up, the hierarchy is wrong. I was immediately numb.
Of course, even if it is so difficult, there is a way. Introjs implementation case: http://jsrun.net/KAQKp/edit , although compatibility may be worrying .
Dismantling function points
Although there are plugins, we can also see how to implement it. Let's break it down
Highlight function & mask function
-
fixed
+z-index
level -
box-shadow
-
border
+ displacement
-
- Get the element position for easy positioning
- Callbacks such as the previous step and the next step are convenient for processing logic.
Highlight function & mask function
https://jsrun.net/cRQKp/edit
You can see that it is basically satisfied, but the bottom is still clickable. And there are no layers .
The layering function is achieved by adding a mask layer, so that the event can be blocked. https://jsrun.net/duQKp/edit
But there is still a problem here. z-index
cannot exceed parent . So we need to add multiple layers to circumvent this problem.
Get element position popper positioning
We can use some third-party libraries to implement the function of popper
- popper.js
https://jsrun.net/duQKp/edit Soon we achieved what we wanted. Implemented by offsetParent and recursive parentNode.
absolute + event (pageY)
tooltip.style.position = 'absolute'; tooltip.style.top = `${e.pageY}px`; tooltip.style.left = `${e.pageX}px`;
fixed + event (clientY)
tooltip.style.position = 'fixed'; tooltip.style.top = `${e.clientY}px`; tooltip.style.left = `${e.clientX}px`;
absolute + recursive offset
const getOffestValue = function getOffestValue(el, offsetLeft="offsetLeft"){ if(!el) return 0; return el[offsetLeft] + (getOffestValue(el.offsetParent, offsetLeft) || 0) } tooltip.style.position = 'absolute'; tooltip.style.top = `${getOffestValue(el, 'offsetTop') - 30}px`; tooltip.style.left = `${getOffestValue(el) - 20}px`;
- fixed + getBoundingClientRect
const {x,y} = el.getBoundingClientRect() tooltip.style.position = 'fixed'; tooltip.style.top = `${y - 30}px`; tooltip.style.left = `${x - 30}px`;
callback logic
Can be thrown via bus or $emit.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。