Try the following conditions:
if (y >= top && z <= bottom) { // if so, add the fixed class $('#buttonsDiv').addClass('fixed'); } else if(z > bottom) { // otherwise remove it $('#buttonsDiv').removeClass('fixed').addClass('absolute'); } else { // otherwise remove it $('#buttonsDiv').removeClass('fixed'); }
Once you scroll through the DIV container (#mainBody), the floating DIV (#buttonsDiv) should be positioned βabsoluteβ to the bottom of the DIV container.
source share