From 746fc57c1d254f8979a4e227494e83445dc52e57 Mon Sep 17 00:00:00 2001 From: Chris Oyler Date: Wed, 23 Dec 2015 14:30:02 -0800 Subject: [PATCH] fixes issue in sticky where calling data-sticky with no anchor points would incorrectly cause it to remain sticky only for the height of the view, not the height of the document. Remedied with a new buff to the _parsePoints method. No anchor sticky will start at 1px (minimum required) and remain sticky till the end of the document. --- js/foundation.sticky.js | 49 +++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/js/foundation.sticky.js b/js/foundation.sticky.js index 65b348bf5..f83ee9ca1 100644 --- a/js/foundation.sticky.js +++ b/js/foundation.sticky.js @@ -25,7 +25,7 @@ /** * Customizable container template. Add your own classes for styling and sizing. * @option - * @example '
' + * @example '<div data-sticky-container class="small-6 columns"></div>' */ container: '
', /** @@ -112,15 +112,14 @@ this.scrollCount = this.options.checkEvery; this.isStuck = false; - // console.log(this.options.anchor, this.options.topAnchor); - if(this.options.topAnchor !== ''){ - this._parsePoints(); - // console.log(this.points[0]); + + if(this.options.anchor !== ''){ + this.$anchor = $('#' + this.options.anchor); }else{ - this.$anchor = this.options.anchor ? $('#' + this.options.anchor) : $(document.body); + this._parsePoints(); } - + console.log(this.points); this._setSizes(function(){ _this._calc(false); }); @@ -136,20 +135,25 @@ btm = this.options.btmAnchor, pts = [top, btm], breaks = {}; - for(var i = 0, len = pts.length; i < len && pts[i]; i++){ - var pt; - if(typeof pts[i] === 'number'){ - pt = pts[i]; - }else{ - var place = pts[i].split(':'), - anchor = $('#' + place[0]); - - pt = anchor.offset().top; - if(place[1] && place[1].toLowerCase() === 'bottom'){ - pt += anchor[0].getBoundingClientRect().height; + if(top && btm){ + + for(var i = 0, len = pts.length; i < len && pts[i]; i++){ + var pt; + if(typeof pts[i] === 'number'){ + pt = pts[i]; + }else{ + var place = pts[i].split(':'), + anchor = $('#' + place[0]); + + pt = anchor.offset().top; + if(place[1] && place[1].toLowerCase() === 'bottom'){ + pt += anchor[0].getBoundingClientRect().height; + } } + breaks[i] = pt; } - breaks[i] = pt; + }else{ + breaks = {0: 1, 1: document.documentElement.scrollHeight}; } // console.log(breaks); this.points = breaks; @@ -168,13 +172,6 @@ if(this.isOn){ return; } if(this.canStick){ this.isOn = true; - // this.$anchor.off('change.zf.sticky') - // .on('change.zf.sticky', function(){ - // _this._setSizes(function(){ - // _this._calc(false); - // }); - // }); - $(window).off(scrollListener) .on(scrollListener, function(e){ if(_this.scrollCount === 0){ -- 2.47.2