From 61ca4dc728a7b1a997b0ac87622237d20df7672f Mon Sep 17 00:00:00 2001 From: Nav Garcha Date: Fri, 12 Jul 2013 14:20:50 +0100 Subject: [PATCH 1/8] Fixed issue with left position not being reset to original value after scrolling container --- jquery.pin.js | 2 +- jquery.pin.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.pin.js b/jquery.pin.js index d9adef4..2f675ef 100644 --- a/jquery.pin.js +++ b/jquery.pin.js @@ -64,7 +64,7 @@ if (options.activeClass) { $this.addClass(options.activeClass); } } else if (scrollY >= to) { $this.css({ - left: "auto", + left: "", top: to - data.parentTop }).css("position", "absolute"); if (options.activeClass) { $this.addClass(options.activeClass); } diff --git a/jquery.pin.min.js b/jquery.pin.min.js index efc9dd1..fd93583 100644 --- a/jquery.pin.min.js +++ b/jquery.pin.min.js @@ -1 +1 @@ -(function(e){"use strict";e.fn.pin=function(t){var n=0,r=[],i=!1;t=t||{};var s=function(){for(var n=0,s=r.length;n"),o.data("pin",{from:t.containerSelector?f.top:a.top,to:f.top+u.height()-o.outerHeight(),end:f.top+u.height(),parentTop:l.top}),o.css({width:o.outerWidth()}),o.parent().css("height",o.outerHeight())}},o=function(){if(i)return;n=window.scrollY;for(var t=0,s=r.length;tu.end){o.css("position","");continue}an?o.css("position")!="fixed"&&o.css({left:o.offset().left,top:0}).css("position","fixed"):n>=f?o.css({left:"auto",top:f-u.parentTop}).css("position","absolute"):o.css({position:"",top:"",left:""})}},u=function(){s(),o()};return this.each(function(){var t=e(this),n=e(this).data("pin")||{};if(n&&n.update)return;r.push(t),e("img",this).one("load",s),n.update=u,e(this).data("pin",n)}),e(window).scroll(o),e(window).resize(function(){s()}),s(),e(window).load(u),this}})(jQuery); \ No newline at end of file +(function(e){"use strict";e.fn.pin=function(t){var n=0,r=[],i=!1;t=t||{};var s=function(){for(var n=0,s=r.length;n"),o.data("pin",{from:t.containerSelector?f.top:a.top,to:f.top+u.height()-o.outerHeight(),end:f.top+u.height(),parentTop:l.top}),o.css({width:o.outerWidth()}),o.parent().css("height",o.outerHeight())}},o=function(){if(i)return;n=window.scrollY;for(var t=0,s=r.length;tu.end){o.css("position","");continue}an?o.css("position")!="fixed"&&o.css({left:o.offset().left,top:0}).css("position","fixed"):n>=f?o.css({left:"",top:f-u.parentTop}).css("position","absolute"):o.css({position:"",top:"",left:""})}},u=function(){s(),o()};return this.each(function(){var t=e(this),n=e(this).data("pin")||{};if(n&&n.update)return;r.push(t),e("img",this).one("load",s),n.update=u,e(this).data("pin",n)}),e(window).scroll(o),e(window).resize(function(){s()}),s(),e(window).load(u),this}})(jQuery); \ No newline at end of file From 0258ee00b7e8c5bcaa9d35241706709988f249c6 Mon Sep 17 00:00:00 2001 From: cchantep Date: Thu, 14 Nov 2013 14:31:03 +0100 Subject: [PATCH 2/8] Workaround for removed elements --- jquery.pin.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jquery.pin.js b/jquery.pin.js index 2f675ef..7e43198 100644 --- a/jquery.pin.js +++ b/jquery.pin.js @@ -44,11 +44,19 @@ if (disabled) { return; } scrollY = $window.scrollTop(); - + + var elmts = []; for (var i=0, len=elements.length; i data.end) { @@ -73,6 +81,7 @@ if (options.activeClass) { $this.removeClass(options.activeClass); } } } + elements = elmts; }; var update = function () { recalculateLimits(); onScroll(); }; @@ -96,4 +105,4 @@ return this; }; -})(jQuery); \ No newline at end of file +})(jQuery); From 5567616e41c4afcf868031392a6d7e9044355908 Mon Sep 17 00:00:00 2001 From: David Wolever Date: Sun, 29 Dec 2013 20:13:28 -0500 Subject: [PATCH 3/8] Add 'padding' option --- README.md | 6 +++++- jquery.pin.js | 14 ++++++++++---- jquery.pin.min.js | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 65afee3..f900047 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ To make a pinned element stay within an outer container, use the containerSelect $(".pinned").pin({containerSelector: ".container"}) +Padding can also be added around the pinned element while scrolling: + + $(".pinned").pin({padding: {top: 10, bottom: 10}}) + That's it - go pin all the things! ## Examples @@ -29,4 +33,4 @@ Redistribution and use in source and binary forms, with or without modification, Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/jquery.pin.js b/jquery.pin.js index 7e43198..30aa09a 100644 --- a/jquery.pin.js +++ b/jquery.pin.js @@ -28,9 +28,15 @@ $this.wrap("
"); } + var pad = $.extend({ + top: 0, + bottom: 0 + }, options.padding || {}); + $this.data("pin", { - from: options.containerSelector ? containerOffset.top : offset.top, - to: containerOffset.top + $container.height() - $this.outerHeight(), + pad: pad, + from: (options.containerSelector ? containerOffset.top : offset.top) - pad.top, + to: containerOffset.top + $container.height() - $this.outerHeight() - pad.bottom, end: containerOffset.top + $container.height(), parentTop: parentOffset.top }); @@ -67,13 +73,13 @@ if (from < scrollY && to > scrollY) { !($this.css("position") == "fixed") && $this.css({ left: $this.offset().left, - top: 0 + top: data.pad.top }).css("position", "fixed"); if (options.activeClass) { $this.addClass(options.activeClass); } } else if (scrollY >= to) { $this.css({ left: "", - top: to - data.parentTop + top: to - data.parentTop + data.pad.top }).css("position", "absolute"); if (options.activeClass) { $this.addClass(options.activeClass); } } else { diff --git a/jquery.pin.min.js b/jquery.pin.min.js index fd93583..f22dcea 100644 --- a/jquery.pin.min.js +++ b/jquery.pin.min.js @@ -1 +1,4 @@ -(function(e){"use strict";e.fn.pin=function(t){var n=0,r=[],i=!1;t=t||{};var s=function(){for(var n=0,s=r.length;n"),o.data("pin",{from:t.containerSelector?f.top:a.top,to:f.top+u.height()-o.outerHeight(),end:f.top+u.height(),parentTop:l.top}),o.css({width:o.outerWidth()}),o.parent().css("height",o.outerHeight())}},o=function(){if(i)return;n=window.scrollY;for(var t=0,s=r.length;tu.end){o.css("position","");continue}an?o.css("position")!="fixed"&&o.css({left:o.offset().left,top:0}).css("position","fixed"):n>=f?o.css({left:"",top:f-u.parentTop}).css("position","absolute"):o.css({position:"",top:"",left:""})}},u=function(){s(),o()};return this.each(function(){var t=e(this),n=e(this).data("pin")||{};if(n&&n.update)return;r.push(t),e("img",this).one("load",s),n.update=u,e(this).data("pin",n)}),e(window).scroll(o),e(window).resize(function(){s()}),s(),e(window).load(u),this}})(jQuery); \ No newline at end of file +(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"); +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;df.end?c.css("position",""):jg?("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); From 7abf2e4c69b1fdaf962fa6f69682fdf530c7b7a3 Mon Sep 17 00:00:00 2001 From: Camzilla Date: Wed, 27 Aug 2014 10:45:39 +0200 Subject: [PATCH 4/8] Substracted padding variables to bottom and top container * Fixed issue with that adding padding makes pinned element overlap container --- jquery.pin.js | 4 ++-- jquery.pin.min.js | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/jquery.pin.js b/jquery.pin.js index 30aa09a..97d25c8 100644 --- a/jquery.pin.js +++ b/jquery.pin.js @@ -62,8 +62,8 @@ elmts.push($this); - var from = data.from, - to = data.to; + var from = data.from - data.pad.bottom, + to = data.to - data.pad.top; if (from + $this.outerHeight() > data.end) { $this.css('position', ''); diff --git a/jquery.pin.min.js b/jquery.pin.min.js index f22dcea..04cc68d 100644 --- a/jquery.pin.min.js +++ b/jquery.pin.min.js @@ -1,4 +1 @@ -(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"); -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;df.end?c.css("position",""):jg?("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); +(function(e){"use strict";e.fn.pin=function(t){var n=0,r=[],i=false,s=e(window);t=t||{};var o=function(){for(var n=0,o=r.length;n")}var h=e.extend({top:0,bottom:0},t.padding||{});u.data("pin",{pad:h,from:(t.containerSelector?l.top:f.top)-h.top,to:l.top+a.height()-u.outerHeight()-h.bottom,end:l.top+a.height(),parentTop:c.top});u.css({width:u.outerWidth()});u.parent().css("height",u.outerHeight())}};var u=function(){if(i){return}n=s.scrollTop();var o=[];for(var u=0,a=r.length;ul.end){f.css("position","");continue}if(cn){!(f.css("position")=="fixed")&&f.css({left:f.offset().left,top:l.pad.top}).css("position","fixed");if(t.activeClass){f.addClass(t.activeClass)}}else if(n>=h){f.css({left:"",top:h-l.parentTop+l.pad.top}).css("position","absolute");if(t.activeClass){f.addClass(t.activeClass)}}else{f.css({position:"",top:"",left:""});if(t.activeClass){f.removeClass(t.activeClass)}}}r=o};var a=function(){o();u()};this.each(function(){var t=e(this),n=e(this).data("pin")||{};if(n&&n.update){return}r.push(t);e("img",this).one("load",o);n.update=a;e(this).data("pin",n)});s.scroll(u);s.resize(function(){o()});o();s.load(a);return this}})(jQuery) \ No newline at end of file From 33114e31fdc4fa71bdd385bbd8488027558ddc0f Mon Sep 17 00:00:00 2001 From: Aris FM Date: Tue, 6 Jan 2015 18:47:55 +0700 Subject: [PATCH 5/8] add bower.json --- bower.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..c879783 --- /dev/null +++ b/bower.json @@ -0,0 +1,28 @@ +{ + "name": "jquery.pin", + "main": "jquery.pin.js", + "version": "1.0.3", + "homepage": "https://github.com/webpop/jquery.pin", + "authors": [ + "Mathias Biilmann " + ], + "description": "jQuery.Pin is a plugin to pin any element within a container", + "keywords": [ + "pin", + "sticky", + "jquery", + "sticky", + "plugin", + "jquery", + "pin", + "plugin" + ], + "license": "The BSD 2-Clause License", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} From 2274a00b665e21805057d045d9d95a44d739a0a5 Mon Sep 17 00:00:00 2001 From: Aris FM Date: Tue, 6 Jan 2015 19:02:23 +0700 Subject: [PATCH 6/8] Update bower.json --- bower.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index c879783..06b85cc 100644 --- a/bower.json +++ b/bower.json @@ -6,16 +6,13 @@ "authors": [ "Mathias Biilmann " ], + "dependencies": { + "jquery": ">=1.8.0" + }, "description": "jQuery.Pin is a plugin to pin any element within a container", "keywords": [ "pin", - "sticky", - "jquery", - "sticky", - "plugin", - "jquery", - "pin", - "plugin" + "sticky" ], "license": "The BSD 2-Clause License", "ignore": [ From dcf08bed871bf6acd23b54d30dfd6fe5a2a2ee52 Mon Sep 17 00:00:00 2001 From: Aris FM Date: Tue, 13 Jan 2015 14:38:34 +0700 Subject: [PATCH 7/8] Update bower.json Change homepage --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 06b85cc..ae6f3bd 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "jquery.pin", "main": "jquery.pin.js", "version": "1.0.3", - "homepage": "https://github.com/webpop/jquery.pin", + "homepage": "http://webpop.github.io/jquery.pin/", "authors": [ "Mathias Biilmann " ], From 7aae4cd7fa5b9467ea7efc75909aff8e60446bfc Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Thu, 22 Jan 2015 12:38:08 -0800 Subject: [PATCH 8/8] Update bower version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index ae6f3bd..1d775ac 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery.pin", "main": "jquery.pin.js", - "version": "1.0.3", + "version": "1.0.4", "homepage": "http://webpop.github.io/jquery.pin/", "authors": [ "Mathias Biilmann "