Skip to content

Instantly share code, notes, and snippets.

@cduruk
Created November 21, 2010 08:53
Show Gist options
  • Save cduruk/708582 to your computer and use it in GitHub Desktop.
Save cduruk/708582 to your computer and use it in GitHub Desktop.
floatADivOnDomLoad : function(id, parentid) {
util.doOnDomLoad( function() {
if ($(id)) document.observe('scroll', util.floatADivOnScrollHandler.bind(this,id,parentid));
// this is for the IEs
if (window.attachEvent && $(id)) window.attachEvent("onscroll", util.floatADivOnScrollHandler.bind(this,id, parentid));
});
},
//
floatADivOnScrollHandler : function(id, parentid) {
var b = $(id);
var b_height = b.getHeight();
var par = $(parentid);
var coff = par.cumulativeOffset()[1];
var csoff = par.cumulativeScrollOffset()[1];
var bottom_y = $('page').cumulativeOffset()[1] + $('page').getHeight() - $('page').cumulativeScrollOffset()[1];
if (coff < csoff && b_height < bottom_y)
b.setStyle({
position: 'fixed',
marginTop: '0px'
});
else if (coff < csoff)
b.setStyle({
position: 'fixed',
marginTop: (bottom_y - b_height) + 'px'
})
else
b.setStyle({
position: 'static',
marginTop: '0px'
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment