Click on the anchor link to scroll smoothly and adjust freely to the top position 1. Add anchor points. Note that the a tag uses nacTo instead of href. <ul> <li><a class="anchor" navTo="one">Target selection</a></li> <li><a class="anchor" navTo="two">Target customers</a></li> <li><a class="anchor" navTo="three">Advertising Format</a></li> <li><a class="anchor" navTo="four">Advertising</a></li> <li><a class="anchor" navTo="five">Budget and schedule</a></li> <li><a class="anchor" navTo="six">Conversion Tracking</a></li> </ul> 2. Add the corresponding id to the content that needs to be scrolled on the right <div class="right"> <div id="one"> <div class="target"> <i>Your goal is to:</i> <div class="brand_engagement"><img src="img/signal.png" /><i>Brand Engagement</i><b>Change</b></div> <p>I want people to know about my business. </p> <div class="advertising_that"> <img src="img/right.png" /> Your ad will be shown to the right people most likely to view your ad. </b> </div> </div> </div> <div id="two"> The second part of the content </div> <div id="three"> The third part of the content </div> <div id="four"> The fourth part of the content </div> <div id="five"> The fifth part of the content </div> </div> 3. Add js to smoothly scroll to the top distance (150 is the height of the navigation, which can be adjusted freely as needed) $('.anchor').click(function () { var navto = $(this).attr('navto'); if (navto != "#") { var $div = $('#' + navto); var top = $div.offset().top || 0; $('html,body').animate({ 'scroll-top': top - 150 }, 500); } else { $('html,body').animate({ 'scroll-top': 0 }, 500); } }); OK~ Effect display This is the end of this article about smooth scrolling when clicking on anchor links in JS and freely adjusting to the top position. For more relevant js anchor link smooth scrolling content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of eight ways to optimize MySQL database (classic must-read)
>>: Tutorial on configuring and using i3 window manager in Linux
In MySQL database operations, we always hope to a...
1 Introduction After "Maven deploys Springbo...
Table of contents Previous words Synchronous and ...
Table of contents Achieve results Available plugi...
This article example shares the specific code of ...
The utf8mb4 encoding is a superset of the utf8 en...
Table of contents 1. Build Docker 2. Enter the co...
Linux and Unix are multi-user operating systems, ...
Recorded the installation of mysql-8.0.12-winx64 ...
Simply use CSS to achieve all the effects of corn...
Table of contents 1. What is recursion? 2. Solve ...
Index definition: It is a separate database struc...
<br />Previous article: Seven Principles of ...
1. Change the Host field value of a record in the...
1. Absolute path First of all, on the local compu...