About the front-end page locator

About the front-end page locator

In the last two days, I have encountered a lot of problems in changing the website mall. Today, let’s talk about the usage of the front-end page locator. The following methods are

Pro-test effective

---------- In the text, yourId refers to the element of the id selector you want to locate.

The first

location.href="#yourId";

This is the feeling of instant positioning and flashing, the code is simple, and it is used in js. I like it better.

The second

<a href="#yourId">定位</a>

This is also instant positioning and concise. Preference is used in html pages.

The third

$('html, body').animate({
    
    scrollTop: $('#yourId').offset().top}, 1000)

This is a positioning with an animated sliding effect. The effect is good, but it is hard to remember.
animate: The meaning of animation.
$('html',body).animate(): refers to the animation that the entire html page calls an animate(). {scrollTop: $('#yourId').offset().top} is the first parameter in the animate() method, which means sliding vertically from the top; 1000 is the second parameter, in milliseconds.
So the whole method means that this page calls the animation, and slides to the anchor point (#yourId) within 1 second from the top.

The above are all personal understanding, please give me some suggestions if there is something wrong.

Guess you like

Origin blog.csdn.net/weixin_43901067/article/details/99745785