PDA

View Full Version : scroll until div hits chrome



ggalan
03-05-2011, 07:01 PM
when you go to google news , take alook at the nav on the left.
as you scroll down the page the left nav will move until the div hits the top of the chrome then it stays put while the rest of the page keeps scrolling
how can you do this?

ggalan
03-06-2011, 06:43 PM
heres code for a persistant div, in this case its a navigational area that stays put even when you scroll but i cant seem to modify it like the google page
anyone?



function fixedNav() {
var startX = 0, startY = 0;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
function ml(id) {
var el = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
if(d.layers) el.style=el;
el.sP = function(x,y) {
this.style.left=x+px;
this.style.top=y+px;
};
el.x = startX;
el.y = startY;
return el;
}
window.stayTopLeft=function() {
var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
var dY = (pY > startY) ? pY : startY;
ftlObj.y += (dY - ftlObj.y)/8;
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 5);
}
ftlObj = ml("sidebar");
stayTopLeft();
}