Scroll Down To ElementJquery made scroll down to any element easy but with vanilla javascript you can do it without long or complex code.User Story :When a user clicks on a link in navbar it will take him to the related section.I cut each part of the code and explain it a little.Add event listener to parent element that contains linksSuppose we had div element with class navbar that contains all a elements.Get value ids, data-scroll from element clickedWhen a user clicks, the event fired and reply_click callback function called.So we can use event.srcElement, this object contains many properties related to an element you target, try it in the console.I will use data-scroll property I added to elements. data-scroll values match the ids of sections we have on our page!scrolled element's content vertically when the user clicks.we can use document.documentElement.scrollTop it represents the number of pixels that the element's content has been scrolled vertically .. element here is , so we can increment or decrement pixels vertically.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to


javascript,html,jquery,css