diff --git a/jquery.lockfixed.js b/jquery.lockfixed.js index aa6b8cf..5f697bf 100644 --- a/jquery.lockfixed.js +++ b/jquery.lockfixed.js @@ -34,7 +34,8 @@ max_height = $(document).height() - config.offset.bottom, top = 0, swtch = false, - pos_not_fixed = false; + pos_not_fixed = false, + el_right_float = el.css('float') === 'right';; /* we prefer feature testing, too much hassle for the upside */ /* while prettier to use position: fixed (less jitter when scrolling) */ @@ -46,6 +47,9 @@ $(window).bind('scroll resize orientationchange load',el,function(e){ var el_height = el.outerHeight(), scroll_top = $(window).scrollTop(); + + // check height on load event (specifically) due to elements being hidden on DOM ready - is this case, the height value is incorrect) + max_height = $(document).height() - config.offset.bottom; //if we have a input focus don't change this (for ios zoom and stuff) if(pos_not_fixed && document.activeElement && document.activeElement.nodeName === "INPUT"){ @@ -63,13 +67,13 @@ if (pos_not_fixed){ el.css({'marginTop': parseInt(((el_margin_top ? el_margin_top : 0) + (scroll_top - el_top - top) + 2 * config.offset.top),10)+'px'}); }else{ - el.css({'position': 'fixed','top':(config.offset.top-top)+'px','width':el_width +"px"}); + el.css({'position': 'fixed','top':(config.offset.top-top)+'px','width':el_width +"px",'left':el_right_float ? el_left + "px" : 'auto'}); } }else{ - el.css({'position': el_position,'top': el_position_top, 'width':el_width +"px", 'marginTop': (el_margin_top ? el_margin_top : 0)+"px"}); + el.css({'position': el_position,'top': el_position_top, 'width':el_width +"px", 'marginTop': (el_margin_top ? el_margin_top : 0)+"px",'left':el_right_float ? el_left + "px" : 'auto'}); } }); } } }); -})(jQuery); \ No newline at end of file +})(jQuery);