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
List style properties There are 2 types of lists ...
1. Use the speed control function to control the ...
This article originated from my complaints about ...
Table of contents 1. Project construction 2: Dire...
Table of contents 1. Introduction to Concurrency ...
DOM Concepts DOM: document object model: The docu...
Table of contents background Question 1 Error 2 E...
This article shares the specific code of js to im...
Preface Programming languages usually contain v...
Use native JavaScript to simply implement the cou...
Sometimes MySQL needs to use a function similar t...
Use jQuery to implement form validation, for your...
1.fullpage.js Download address https://github.com...
The simple installation configuration of mysql5.7...
Table of contents Preface Implementation ideas Im...