0

How to smoothly scroll a div to top of the page but just below the header.

I have the code in jquery but I need to convert this to pure java-script and should be working in all the latest browsers.

$('html, body').animate({ scrollTop: $("#mydiv"+id).offset().top - 55 }, 699);

I got the java script function to scroll but not the animation.

document.getElementById('mydiv'+id).scrollIntoView(); scrollBy(0, -55);

Can someone help me here , I need to add a small animation to the scroll. Thanks.

user1846348
  • 241
  • 1
  • 10
  • 22
  • 2
    Why can't you use jQuery? If you want it to work in all the latest browsers it sounds like jQuery (or some DOM abstraction library) is the way to go. – KylePlusPlus Feb 05 '14 at 00:32
  • 3
    You can use `window.scrollTo()` to scroll without animation if you don't wanna use jquery. – AliBZ Feb 05 '14 at 00:33
  • 2
    Check this answer of the animation: http://stackoverflow.com/questions/8917921/cross-browser-javascript-not-jquery-scroll-to-top-animation – AliBZ Feb 05 '14 at 00:36
  • @KylePlusPlus , I dont want to load the jquery coz of it, its hard to debug through the console. – user1846348 Feb 05 '14 at 01:15

0 Answers0