Scroll To Anchor Point Using Js
I use this code to open and switch between different divs. I would need use it to make scroll to an anchor point (it is inside the open div). Is it possible? Thanks a lot.
Solution 1:
Scroll to a particular number of pixels: jsFiddle
var body = document.body; // Safarivar html = document.documentElement; // Chrome, Firefox, IE and Opera places the overflow at the <html> level, unless else is specified. Therefore, we use the documentElement property for these browsers
body.scrollTop += 100;
html.scrollTop += 100;
Scroll to an element: jsFiddle
var elmnt = document.getElementById("scroll");
elmnt.scrollIntoView();
Using your jsFiddle as the example, declare the variable outside of the functions so it is global.
Post a Comment for "Scroll To Anchor Point Using Js"