You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 lines
1.5 KiB
Plaintext

(function(e){e.fn.pin=function(a){var g=0,h=[],n=!1,k=e(window),a=a||{},m=function(){for(var i=0,d=h.length;i<d;i++){var b=h[i];if(a.minWidth&&k.width()<=a.minWidth)b.parent().is(".pin-wrapper")&&b.unwrap(),b.css({width:"",left:"",top:"",position:""}),a.activeClass&&b.removeClass(a.activeClass),n=!0;else{n=!1;var c=a.containerSelector?b.closest(a.containerSelector):e(document.body),f=b.offset(),j=c.offset(),l=b.offsetParent().offset();b.parent().is(".pin-wrapper")||b.wrap("<div class='pin-wrapper'>");
var g=e.extend({top:0,bottom:0},a.padding||{});b.data("pin",{pad:g,from:(a.containerSelector?j.top:f.top)-g.top,to:j.top+c.height()-b.outerHeight()-g.bottom,end:j.top+c.height(),parentTop:l.top});b.css({width:b.outerWidth()});b.parent().css("height",b.outerHeight())}}},o=function(){if(!n){g=k.scrollTop();for(var i=[],d=0,b=h.length;d<b;d++){var c=e(h[d]),f=c.data("pin");if(f){i.push(c);var j=f.from,l=f.to;j+c.outerHeight()>f.end?c.css("position",""):j<g&&l>g?("fixed"!=c.css("position")&&c.css({left:c.offset().left,
top:f.pad.top}).css("position","fixed"),a.activeClass&&c.addClass(a.activeClass)):g>=l?(c.css({left:"",top:l-f.parentTop+f.pad.top}).css("position","absolute"),a.activeClass&&c.addClass(a.activeClass)):(c.css({position:"",top:"",left:""}),a.activeClass&&c.removeClass(a.activeClass))}}h=i}},p=function(){m();o()};this.each(function(){var a=e(this),d=e(this).data("pin")||{};if(!d||!d.update)h.push(a),e("img",this).one("load",m),d.update=p,e(this).data("pin",d)});k.scroll(o);k.resize(function(){m()});
m();k.load(p);return this}})(jQuery);