How to scroll to show part of a webpage
Here is one example of how you can control X / Y scrolling without anchors. (ScrollX / ScrollY)
The key part, I believe, is the following
function saveScrollCoordinates() {
document.Form1.scrollx.value = (document.all)?document.body.scrollLeft:window.pageXOffset;
document.Form1.scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset;
}
a source to share
Using a property (common to all elements), you can scroll to a specific pixel height. Thus, scrolling to the height of a particular anchor would require a request to offset that anchor and set accordingly. Just for the sake of illustration; this is how you can scroll the specified element using jQuery: scrollTop
scrollTop
var top = $('div#something').offset().top;
$(document).scrollTop(top);
NOTE : jQuery implementation can be confusing; it accepts , but the top-most element with a property is , in fact, (usually refers to ). document
scrollTop
document.documentElement
<HTML>
There is also a property for horizontal scrolling. scrollLeft
And of course you can read these properties:
var currentScrollTop = document.documentElement.scrollTop;
a source to share
The prototype implements a function scrollTo()
that makes it very easy to navigate to a specific element:
$("#elementID").scrollTo();
The implementation internally calls window.scrollTo
for the actual scrolling.
a source to share
var coord = {top:null,left:null,width:null,height:null};
if (typeof window.pageYOffset == 'number') {
coord.top = window.pageYOffset; coord.left = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
coord.top = document.body.scrollTop; coord.left = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
coord.top = document.documentElement.scrollTop; coord.left = document.documentElement.scrollLeft;
}
if (typeof window.innerWidth == 'number') {
coord.width = window.innerWidth; coord.height = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
coord.width = document.documentElement.clientWidth; coord.height = document.documentElement.clienthHeight;
} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
coord.width = document.body.clientWidth;
coord.height = document.body.clientHeight;
}
a source to share