Created
November 21, 2010 08:53
-
-
Save cduruk/708582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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