Home. Here is the source code I found good:"/> Home. Here is the source code I found good:">

Home  >  Article  >  Web Front-end  >  js anchor scrolling example sharing

js anchor scrolling example sharing

小云云
小云云Original
2018-03-12 16:09:541281browse

Written with bootstrap. The following is the dry information: The href in each a of each li of ul points to the anchor target, for example, ef5dc968b76d5ea7ce8b8602c8c59a96a92e72f0d0a57d5f978c135d16bfdbe2Home5db79b134e9f6b82c0b36e0489ee08edbed06894275b65c1ab86501b08a632eb. The following is the source code I found:

$('#navbar-menu ul li a[href^="#"]').click(function(e){
                    e.preventDefault();
                    $('html, body').animate({scrollTop: $(this.hash).offset().top}, 400);
                });

Translation: When clicked, the default behavior is first blocked, and then the html, and body scrolling animations are scrolled to The distance from the top is the distance of the target's offset().top, which is completed in 4 milliseconds. The hash attribute is a readable and writable string, which is the anchor part of the URL (the part starting from the # sign), so this.hash refers to the # part of the current address. Regarding the object represented by this, we will summarize it later.
ps:$('body').scrollspy({ target: '#menu-nav' })This bootstrap's scrollspy plug-in automatically monitors the target scrolling and changes the corresponding active, which is very good of.

Related recommendations:

Javascript implementation of navigation anchor scrolling effect

The above is the detailed content of js anchor scrolling example sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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