Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does jquery imitate the anchor to jump to the specified location on the page?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian introduces in detail "jquery how to imitate the anchor point to jump to the specified position on the page", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "jquery how to imitate the anchor point to jump to the specified position on the page" article can help you solve your doubts, following the editor's train of thought slowly in depth, together to learn new knowledge.

Js imitates the anchor point to jump to the specified location on the page, using the offset () method

$(document) .ready (function () {var target_top = $("# qa5"). Offset (). Top; / / $("html,body"). Animate ({scrollTop: target_top}, 1000); / / Jump $("html,body") .scrollTop (target_top);})

JQuery:

Offset ():

Gets the relative offset of the matching element in the current viewport.

The returned object contains two integer properties: top and left. This method is valid only for visible elements.

Position ():

Gets the offset of the matching element from the parent element.

The returned object contains two integer properties: top and left. To calculate the results accurately, use pixel units on padding, border, and fill attributes. This method is valid only for visible elements.

ScrollTop ():

Method sets or returns the vertical scroll bar position of the selected element.

Tip: when the scroll bar is at the top, the position is 0.

When used to return to a position:

This method returns the vertical position of the scroll bar of the first matching element.

When used to set the location:

This method sets the vertical position of the scroll bars of all matching elements.

Read this, the "jquery how to imitate the anchor jump to the designated location of the page" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report