headroom.js
Advanced tools
Comparing version 0.9.3 to 0.9.4
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -157,3 +157,3 @@ */ | ||
// defer event registration to handle browser | ||
// defer event registration to handle browser | ||
// potentially restoring previous scroll position | ||
@@ -172,3 +172,9 @@ setTimeout(this.attachEvent.bind(this), 100); | ||
this.initialised = false; | ||
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.notTop, classes.initial); | ||
for (var key in classes) { | ||
if(classes.hasOwnProperty(key)) { | ||
this.elem.classList.remove(classes[key]); | ||
} | ||
} | ||
this.scroller.removeEventListener('scroll', this.debouncer, false); | ||
@@ -190,3 +196,3 @@ }, | ||
}, | ||
/** | ||
@@ -198,3 +204,3 @@ * Unpins the header if it's currently pinned | ||
classes = this.classes; | ||
if(classList.contains(classes.pinned) || !classList.contains(classes.unpinned)) { | ||
@@ -213,3 +219,3 @@ classList.add(classes.unpinned); | ||
classes = this.classes; | ||
if(classList.contains(classes.unpinned)) { | ||
@@ -228,3 +234,3 @@ classList.remove(classes.unpinned); | ||
classes = this.classes; | ||
if(!classList.contains(classes.top)) { | ||
@@ -243,3 +249,3 @@ classList.add(classes.top); | ||
classes = this.classes; | ||
if(!classList.contains(classes.notTop)) { | ||
@@ -255,3 +261,3 @@ classList.add(classes.notTop); | ||
classes = this.classes; | ||
if(!classList.contains(classes.bottom)) { | ||
@@ -270,3 +276,3 @@ classList.add(classes.bottom); | ||
classes = this.classes; | ||
if(!classList.contains(classes.notBottom)) { | ||
@@ -333,3 +339,3 @@ classList.add(classes.notBottom); | ||
documentElement = document.documentElement; | ||
return Math.max( | ||
@@ -373,3 +379,3 @@ body.scrollHeight, documentElement.scrollHeight, | ||
pastBottom = currentScrollY + this.getScrollerPhysicalHeight() > this.getScrollerHeight(); | ||
return pastTop || pastBottom; | ||
@@ -376,0 +382,0 @@ }, |
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
*/ | ||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Headroom=b()}(this,function(){"use strict";function a(a){this.callback=a,this.ticking=!1}function b(a){return a&&"undefined"!=typeof window&&(a===window||a.nodeType)}function c(a){if(arguments.length<=0)throw new Error("Missing arguments in extend function");var d,e,f=a||{};for(e=1;e<arguments.length;e++){var g=arguments[e]||{};for(d in g)"object"!=typeof f[d]||b(f[d])?f[d]=f[d]||g[d]:f[d]=c(f[d],g[d])}return f}function d(a){return a===Object(a)?a:{down:a,up:a}}function e(a,b){b=c(b,e.options),this.lastKnownScrollY=0,this.elem=a,this.tolerance=d(b.tolerance),this.classes=b.classes,this.offset=b.offset,this.scroller=b.scroller,this.initialised=!1,this.onPin=b.onPin,this.onUnpin=b.onUnpin,this.onTop=b.onTop,this.onNotTop=b.onNotTop,this.onBottom=b.onBottom,this.onNotBottom=b.onNotBottom}var f={bind:!!function(){}.bind,classList:"classList"in document.documentElement,rAF:!!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame)};return window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,a.prototype={constructor:a,update:function(){this.callback&&this.callback(),this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},e.prototype={constructor:e,init:function(){return e.cutsTheMustard?(this.debouncer=new a(this.update.bind(this)),this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this):void 0},destroy:function(){var a=this.classes;this.initialised=!1,this.elem.classList.remove(a.unpinned,a.pinned,a.top,a.notTop,a.initial),this.scroller.removeEventListener("scroll",this.debouncer,!1)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,this.scroller.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var a=this.elem.classList,b=this.classes;!a.contains(b.pinned)&&a.contains(b.unpinned)||(a.add(b.unpinned),a.remove(b.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var a=this.elem.classList,b=this.classes;a.contains(b.unpinned)&&(a.remove(b.unpinned),a.add(b.pinned),this.onPin&&this.onPin.call(this))},top:function(){var a=this.elem.classList,b=this.classes;a.contains(b.top)||(a.add(b.top),a.remove(b.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notTop)||(a.add(b.notTop),a.remove(b.top),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.bottom)||(a.add(b.bottom),a.remove(b.notBottom),this.onBottom&&this.onBottom.call(this))},notBottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notBottom)||(a.add(b.notBottom),a.remove(b.bottom),this.onNotBottom&&this.onNotBottom.call(this))},getScrollY:function(){return void 0!==this.scroller.pageYOffset?this.scroller.pageYOffset:void 0!==this.scroller.scrollTop?this.scroller.scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop},getViewportHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},getElementPhysicalHeight:function(a){return Math.max(a.offsetHeight,a.clientHeight)},getScrollerPhysicalHeight:function(){return this.scroller===window||this.scroller===document.body?this.getViewportHeight():this.getElementPhysicalHeight(this.scroller)},getDocumentHeight:function(){var a=document.body,b=document.documentElement;return Math.max(a.scrollHeight,b.scrollHeight,a.offsetHeight,b.offsetHeight,a.clientHeight,b.clientHeight)},getElementHeight:function(a){return Math.max(a.scrollHeight,a.offsetHeight,a.clientHeight)},getScrollerHeight:function(){return this.scroller===window||this.scroller===document.body?this.getDocumentHeight():this.getElementHeight(this.scroller)},isOutOfBounds:function(a){var b=0>a,c=a+this.getScrollerPhysicalHeight()>this.getScrollerHeight();return b||c},toleranceExceeded:function(a,b){return Math.abs(a-this.lastKnownScrollY)>=this.tolerance[b]},shouldUnpin:function(a,b){var c=a>this.lastKnownScrollY,d=a>=this.offset;return c&&d&&b},shouldPin:function(a,b){var c=a<this.lastKnownScrollY,d=a<=this.offset;return c&&b||d},update:function(){var a=this.getScrollY(),b=a>this.lastKnownScrollY?"down":"up",c=this.toleranceExceeded(a,b);this.isOutOfBounds(a)||(a<=this.offset?this.top():this.notTop(),a+this.getViewportHeight()>=this.getScrollerHeight()?this.bottom():this.notBottom(),this.shouldUnpin(a,c)?this.unpin():this.shouldPin(a,c)&&this.pin(),this.lastKnownScrollY=a)}},e.options={tolerance:{up:0,down:0},offset:0,scroller:window,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},e.cutsTheMustard="undefined"!=typeof f&&f.rAF&&f.bind&&f.classList,e}); | ||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Headroom=b()}(this,function(){"use strict";function a(a){this.callback=a,this.ticking=!1}function b(a){return a&&"undefined"!=typeof window&&(a===window||a.nodeType)}function c(a){if(arguments.length<=0)throw new Error("Missing arguments in extend function");var d,e,f=a||{};for(e=1;e<arguments.length;e++){var g=arguments[e]||{};for(d in g)"object"!=typeof f[d]||b(f[d])?f[d]=f[d]||g[d]:f[d]=c(f[d],g[d])}return f}function d(a){return a===Object(a)?a:{down:a,up:a}}function e(a,b){b=c(b,e.options),this.lastKnownScrollY=0,this.elem=a,this.tolerance=d(b.tolerance),this.classes=b.classes,this.offset=b.offset,this.scroller=b.scroller,this.initialised=!1,this.onPin=b.onPin,this.onUnpin=b.onUnpin,this.onTop=b.onTop,this.onNotTop=b.onNotTop,this.onBottom=b.onBottom,this.onNotBottom=b.onNotBottom}var f={bind:!!function(){}.bind,classList:"classList"in document.documentElement,rAF:!!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame)};return window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,a.prototype={constructor:a,update:function(){this.callback&&this.callback(),this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},e.prototype={constructor:e,init:function(){if(e.cutsTheMustard)return this.debouncer=new a(this.update.bind(this)),this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this},destroy:function(){var a=this.classes;this.initialised=!1;for(var b in a)a.hasOwnProperty(b)&&this.elem.classList.remove(a[b]);this.scroller.removeEventListener("scroll",this.debouncer,!1)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,this.scroller.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var a=this.elem.classList,b=this.classes;!a.contains(b.pinned)&&a.contains(b.unpinned)||(a.add(b.unpinned),a.remove(b.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var a=this.elem.classList,b=this.classes;a.contains(b.unpinned)&&(a.remove(b.unpinned),a.add(b.pinned),this.onPin&&this.onPin.call(this))},top:function(){var a=this.elem.classList,b=this.classes;a.contains(b.top)||(a.add(b.top),a.remove(b.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notTop)||(a.add(b.notTop),a.remove(b.top),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.bottom)||(a.add(b.bottom),a.remove(b.notBottom),this.onBottom&&this.onBottom.call(this))},notBottom:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notBottom)||(a.add(b.notBottom),a.remove(b.bottom),this.onNotBottom&&this.onNotBottom.call(this))},getScrollY:function(){return void 0!==this.scroller.pageYOffset?this.scroller.pageYOffset:void 0!==this.scroller.scrollTop?this.scroller.scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop},getViewportHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},getElementPhysicalHeight:function(a){return Math.max(a.offsetHeight,a.clientHeight)},getScrollerPhysicalHeight:function(){return this.scroller===window||this.scroller===document.body?this.getViewportHeight():this.getElementPhysicalHeight(this.scroller)},getDocumentHeight:function(){var a=document.body,b=document.documentElement;return Math.max(a.scrollHeight,b.scrollHeight,a.offsetHeight,b.offsetHeight,a.clientHeight,b.clientHeight)},getElementHeight:function(a){return Math.max(a.scrollHeight,a.offsetHeight,a.clientHeight)},getScrollerHeight:function(){return this.scroller===window||this.scroller===document.body?this.getDocumentHeight():this.getElementHeight(this.scroller)},isOutOfBounds:function(a){var b=a<0,c=a+this.getScrollerPhysicalHeight()>this.getScrollerHeight();return b||c},toleranceExceeded:function(a,b){return Math.abs(a-this.lastKnownScrollY)>=this.tolerance[b]},shouldUnpin:function(a,b){var c=a>this.lastKnownScrollY,d=a>=this.offset;return c&&d&&b},shouldPin:function(a,b){var c=a<this.lastKnownScrollY,d=a<=this.offset;return c&&b||d},update:function(){var a=this.getScrollY(),b=a>this.lastKnownScrollY?"down":"up",c=this.toleranceExceeded(a,b);this.isOutOfBounds(a)||(a<=this.offset?this.top():this.notTop(),a+this.getViewportHeight()>=this.getScrollerHeight()?this.bottom():this.notBottom(),this.shouldUnpin(a,c)?this.unpin():this.shouldPin(a,c)&&this.pin(),this.lastKnownScrollY=a)}},e.options={tolerance:{up:0,down:0},offset:0,scroller:window,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},e.cutsTheMustard="undefined"!=typeof f&&f.rAF&&f.bind&&f.classList,e}); |
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* headroom.js v0.9.3 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2016 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it | ||
* Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js | ||
* License: MIT | ||
@@ -5,0 +5,0 @@ */ |
{ | ||
"name": "headroom.js", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "Give your page some headroom. Hide your header until you need it", | ||
@@ -5,0 +5,0 @@ "main": "dist/headroom.js", |
@@ -47,3 +47,3 @@ # [Headroom.js](http://wicky.nillia.ms/headroom.js) | ||
```bash | ||
bower install https://npmcdn.com/headroom.js/bower.zip --save | ||
bower install https://unpkg.com/headroom.js/bower.zip --save | ||
``` | ||
@@ -53,5 +53,5 @@ | ||
A universal build (suitable for script tags, CommonJS, and AMD) is available from npmcdn.com: | ||
A universal build (suitable for script tags, CommonJS, and AMD) is available from unpkg.com: | ||
[https://npmcdn.com/headroom.js](https://npmcdn.com/headroom.js) | ||
[https://unpkg.com/headroom.js](https://unpkg.com/headroom.js) | ||
@@ -58,0 +58,0 @@ ### With pure JS |
533
32004