forked from ymschaap/jquery-lockfixed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.lockfixed.min.js
13 lines (13 loc) · 1.3 KB
/
jquery.lockfixed.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*!
* jQuery lockfixed plugin
* http://www.directlyrics.com/code/lockfixed/
*
* Copyright 2012 Yvo Schaap
* Released under the MIT license
* http://www.directlyrics.com/code/lockfixed/license.txt
*
* Date: Sun Feb 9 2014 12:00:01 GMT
*/
(function(e,p){e.extend({lockfixed:function(a,b){b&&b.offset?(b.offset.bottom=parseInt(b.offset.bottom,10),b.offset.top=parseInt(b.offset.top,10)):b.offset={bottom:100,top:0};if((a=e(a))&&a.offset()){var n=a.css("position"),c=parseInt(a.css("marginTop"),10),l=a.css("top"),h=a.offset().top,f=!1;if(!0===b.forcemargin||navigator.userAgent.match(/\bMSIE (4|5|6)\./)||navigator.userAgent.match(/\bOS ([0-9])_/)||navigator.userAgent.match(/\bAndroid ([0-9])\./i))f=!0;e(window).bind("scroll resize orientationchange load lockfixed:pageupdate",
a,function(k){if(!f||!document.activeElement||"INPUT"!==document.activeElement.nodeName){var d=0,d=a.outerHeight();k=a.outerWidth();var m=e(document).height()-b.offset.bottom,g=e(window).scrollTop();"fixed"===a.css("position")||f||(h=a.offset().top,l=a.css("top"));g>=h-(c?c:0)-b.offset.top?(d=m<g+d+c+b.offset.top?g+d+c+b.offset.top-m:0,f?a.css({marginTop:parseInt(g-h-d,10)+2*b.offset.top+"px"}):a.css({position:"fixed",top:b.offset.top-d+"px",width:k+"px"})):a.css({position:n,top:l,width:k+"px",marginTop:(c&&
!f?c:0)+"px"})}})}}})})(jQuery);