Home >WeChat Applet >Mini Program Development >JS code to simulate anchor point jump
This article mainly shares an example of using JS to simulate anchor point jump. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
A-HTML anchor point definition:
Set anchor:
<a href="#mao" rel="external nofollow" >&nsbp;</a>
Set point: (For browser compatibility, id and name are set together)
<a id="mao" name="mao">跳至第一个锚点</a>
B: Use JS to simulate anchor point jump:
location.href in js can jump to a certain url;
1, window.location.href = window. location.href + "#mao";
2, window.location.hash = "#mao";
Note: The hash will only be used when jumping to this page for the first time. Function, refreshing this page again will not work, but href always works
Related recommendations:
How to achieve fast positioning on the page in JS (anchor jump problem)
jQuery anchor jump scroll bar smooth scrolling one sentence code
About anchor jump and related operations and plug-ins under jQuery_jquery
The above is the detailed content of JS code to simulate anchor point jump. For more information, please follow other related articles on the PHP Chinese website!