/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//native elem.scrollIntoView() works similar to an #anchor, putting top-left of element at top-left of viewport //set document scroll position //optionally, specify a particular window/frame function setDocumentScrollPosition(top, left, windowFrame) { windowFrame = windowFrame || window; var w = new WindowDimensions(windowFrame); if(isNaN(top)) top = w.window.scroll.top; if(isNaN(left)) left = w.window.scroll.left; //note: window.pageX/YOffset is read-only; the other two seem to depend on whether the browser is in quirks mode or not windowFrame.document.body.scrollLeft = left; windowFrame.document.documentElement.scrollLeft = left; windowFrame.document.body.scrollTop = top; windowFrame.document.documentElement.scrollTop = top; } //set element scroll position function setScrollPosition(elem, top, left) { elem.scrollLeft = left; elem.scrollTop = top; } var scrollUP, panDown, scrollDown, panUp, scrollLeft, panRight, scrollRight, panLeft; scrollUp = panDown = function(elem, distance){ elem.scrollTop -= distance; }; scrollDown = panUp = function(elem, distance){ elem.scrollTop += distance; }; scrollLeft = panRight = function(elem, distance){ elem.scrollLeft -= distance; }; scrollRight = panLeft = function(elem, distance){ elem.scrollLeft += distance; };