Home > WeChat Applet > Mini Program Development > JS code to simulate anchor point jump

JS code to simulate anchor point jump

小云云
Release: 2018-02-02 10:14:02
Original
2526 people have browsed it

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>
Copy after login

Set point: (For browser compatibility, id and name are set together)

<a id="mao" name="mao">跳至第一个锚点</a>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template