document.body.scrollTop
does not work in IE6 if the document's doctype is defined as <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
To find out the scrolling offset in a way that works for both DTD3 and DTD4.01 you can use(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)
Same goes for scrollLeft.See more at document.body.scrollTop in IE
Even more details here:
ReplyDeletehttp://www.quirksmode.org/viewport/compatibility.html
It works awful, thanks a lot.
ReplyDeleteMy function for update position of an element with mouse movement (after your excellent contribution) looks like:
function updatePos(e){
var objFlow = document.getElementById('sumarizado');
if(document.captureEvents){
objFlow.style.left = (e.pageX - 250) + "px";
objFlow.style.top = (e.pageY) + "px";
}else{
objFlow.style.left = event.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft) - 250;
objFlow.style.top = event.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
}
}
You are a complete life-saver - thanks.
ReplyDeleteexcellent solution, thanks
ReplyDeletethanks, used this like this....
ReplyDelete$("button").click(function(){
var scrollTop = (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
alert( scrollTop + " px");
});
ie, chrome, and firefox all worked
thanks!
onto saving as php variable and post back to self to remember where user was on form when submit occured