cleversticky
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -13,3 +13,2 @@ import { ElementType } from "./types"; | ||
private getElHeight; | ||
private getScrollY; | ||
private getStickyEnd; | ||
@@ -20,2 +19,3 @@ private setTopStyle; | ||
private isTallerThanViewport; | ||
private calculateNewTop; | ||
private onWindowScroll; | ||
@@ -22,0 +22,0 @@ private onWindowResize; |
@@ -1,2 +0,2 @@ | ||
(()=>{var s=()=>window?.innerHeight??0,o=r=>r?.clientHeight??0;var h=class{_el;elHeight;resizeObserver;scrollY;stickyEnd;top;windowHeight;get el(){return this._el}constructor(t){this.scrollY=this.getScrollY(),this.windowHeight=s(),this._el=typeof t!="string"?t:document.querySelector(t),this.elHeight=this.getElHeight(),this.resizeObserver=null,this.stickyEnd=this.getStickyEnd(),this.top=0}getElHeight(){return o(this._el)}getScrollY(){let t=window.scrollY;return t<=0?0:t}getStickyEnd(t){return((typeof t=="undefined"?this.windowHeight:t)-this.elHeight)*-1}setTopStyle(t){this._el&&(this._el.style.top=t)}applyTopStyle(){this.setTopStyle(`${this.top*-1}px`)}resetTop(){this.setTopStyle(""),this.top=0}isTallerThanViewport(){return this.elHeight>this.windowHeight}onWindowScroll=()=>{let t=this.getScrollY();if(this.isTallerThanViewport()){if(t!==this.scrollY){let i=t>this.scrollY,e=Math.abs(this.scrollY-t);i?this.top=Math.min(this.top+e,this.stickyEnd):this.top=Math.max(this.top-e,0),this.applyTopStyle()}}else this.resetTop();this.scrollY=t};onWindowResize=()=>{let t=s();if(this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(t),this.isTallerThanViewport()){if(this.windowHeight!==t){let i=t>this.windowHeight,e=Math.abs(this.windowHeight-t);i?this.top=Math.min(this.top+e,this.stickyEnd):this.top=Math.max(this.top-e,0),this.applyTopStyle()}}else this.resetTop();this.scrollY=this.getScrollY(),this.windowHeight=t};onElementResize=()=>{this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(),this.isTallerThanViewport()||this.resetTop()};init(){this._el&&(window.addEventListener("resize",this.onWindowResize),window.addEventListener("scroll",this.onWindowScroll),this.resizeObserver=new ResizeObserver(this.onElementResize),this.resizeObserver.observe(this._el))}destroy(){window.removeEventListener("resize",this.onWindowResize),window.removeEventListener("scroll",this.onWindowScroll),this.resizeObserver&&this.resizeObserver.disconnect(),this._el&&this.resetTop()}};})(); | ||
(()=>{var n=o=>o?.clientHeight??0,s=()=>Math.max(window?.scrollY??0,0),r=()=>window?.innerHeight??0;var h=class{_el;elHeight;resizeObserver;scrollY;stickyEnd;top;windowHeight;get el(){return this._el}constructor(e){this.scrollY=s(),this.windowHeight=r(),this._el=typeof e!="string"?e:document.querySelector(e),this.elHeight=this.getElHeight(),this.resizeObserver=null,this.stickyEnd=this.getStickyEnd(),this.top=0}getElHeight(){return n(this._el)}getStickyEnd(e){return((typeof e=="undefined"?this.windowHeight:e)-this.elHeight)*-1}setTopStyle(e){this._el&&(this._el.style.top=e)}applyTopStyle(){this.setTopStyle(`${this.top*-1}px`)}resetTop(){this.setTopStyle(""),this.top=0}isTallerThanViewport(){return this.elHeight>this.windowHeight}calculateNewTop(e,i){let l=t=>Math.min(this.top+t,this.stickyEnd),p=t=>Math.max(this.top-t,0);if(e!==i){let t=e>i,c=Math.abs(i-e);this.top=(t?l:p)(c),this.applyTopStyle()}}onWindowScroll=()=>{let e=s();this.isTallerThanViewport()?this.calculateNewTop(e,this.scrollY):this.resetTop(),this.scrollY=e};onWindowResize=()=>{let e=r();this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(e),this.isTallerThanViewport()?this.calculateNewTop(e,this.windowHeight):this.resetTop(),this.scrollY=s(),this.windowHeight=e};onElementResize=()=>{this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(),this.isTallerThanViewport()||this.resetTop()};init(){this._el&&(window.addEventListener("resize",this.onWindowResize),window.addEventListener("scroll",this.onWindowScroll),this.resizeObserver=new ResizeObserver(this.onElementResize),this.resizeObserver.observe(this._el))}destroy(){window.removeEventListener("resize",this.onWindowResize),window.removeEventListener("scroll",this.onWindowScroll),this.resizeObserver&&this.resizeObserver.disconnect(),this._el&&this.resetTop()}};})(); | ||
//# sourceMappingURL=index.iife.js.map |
@@ -1,2 +0,2 @@ | ||
var s=()=>window?.innerHeight??0,o=r=>r?.clientHeight??0;var h=class{_el;elHeight;resizeObserver;scrollY;stickyEnd;top;windowHeight;get el(){return this._el}constructor(t){this.scrollY=this.getScrollY(),this.windowHeight=s(),this._el=typeof t!="string"?t:document.querySelector(t),this.elHeight=this.getElHeight(),this.resizeObserver=null,this.stickyEnd=this.getStickyEnd(),this.top=0}getElHeight(){return o(this._el)}getScrollY(){let t=window.scrollY;return t<=0?0:t}getStickyEnd(t){return((typeof t=="undefined"?this.windowHeight:t)-this.elHeight)*-1}setTopStyle(t){this._el&&(this._el.style.top=t)}applyTopStyle(){this.setTopStyle(`${this.top*-1}px`)}resetTop(){this.setTopStyle(""),this.top=0}isTallerThanViewport(){return this.elHeight>this.windowHeight}onWindowScroll=()=>{let t=this.getScrollY();if(this.isTallerThanViewport()){if(t!==this.scrollY){let i=t>this.scrollY,e=Math.abs(this.scrollY-t);i?this.top=Math.min(this.top+e,this.stickyEnd):this.top=Math.max(this.top-e,0),this.applyTopStyle()}}else this.resetTop();this.scrollY=t};onWindowResize=()=>{let t=s();if(this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(t),this.isTallerThanViewport()){if(this.windowHeight!==t){let i=t>this.windowHeight,e=Math.abs(this.windowHeight-t);i?this.top=Math.min(this.top+e,this.stickyEnd):this.top=Math.max(this.top-e,0),this.applyTopStyle()}}else this.resetTop();this.scrollY=this.getScrollY(),this.windowHeight=t};onElementResize=()=>{this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(),this.isTallerThanViewport()||this.resetTop()};init(){this._el&&(window.addEventListener("resize",this.onWindowResize),window.addEventListener("scroll",this.onWindowScroll),this.resizeObserver=new ResizeObserver(this.onElementResize),this.resizeObserver.observe(this._el))}destroy(){window.removeEventListener("resize",this.onWindowResize),window.removeEventListener("scroll",this.onWindowScroll),this.resizeObserver&&this.resizeObserver.disconnect(),this._el&&this.resetTop()}};export{h as default}; | ||
var n=o=>o?.clientHeight??0,s=()=>Math.max(window?.scrollY??0,0),r=()=>window?.innerHeight??0;var h=class{_el;elHeight;resizeObserver;scrollY;stickyEnd;top;windowHeight;get el(){return this._el}constructor(e){this.scrollY=s(),this.windowHeight=r(),this._el=typeof e!="string"?e:document.querySelector(e),this.elHeight=this.getElHeight(),this.resizeObserver=null,this.stickyEnd=this.getStickyEnd(),this.top=0}getElHeight(){return n(this._el)}getStickyEnd(e){return((typeof e=="undefined"?this.windowHeight:e)-this.elHeight)*-1}setTopStyle(e){this._el&&(this._el.style.top=e)}applyTopStyle(){this.setTopStyle(`${this.top*-1}px`)}resetTop(){this.setTopStyle(""),this.top=0}isTallerThanViewport(){return this.elHeight>this.windowHeight}calculateNewTop(e,i){let l=t=>Math.min(this.top+t,this.stickyEnd),p=t=>Math.max(this.top-t,0);if(e!==i){let t=e>i,c=Math.abs(i-e);this.top=(t?l:p)(c),this.applyTopStyle()}}onWindowScroll=()=>{let e=s();this.isTallerThanViewport()?this.calculateNewTop(e,this.scrollY):this.resetTop(),this.scrollY=e};onWindowResize=()=>{let e=r();this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(e),this.isTallerThanViewport()?this.calculateNewTop(e,this.windowHeight):this.resetTop(),this.scrollY=s(),this.windowHeight=e};onElementResize=()=>{this.elHeight=this.getElHeight(),this.stickyEnd=this.getStickyEnd(),this.isTallerThanViewport()||this.resetTop()};init(){this._el&&(window.addEventListener("resize",this.onWindowResize),window.addEventListener("scroll",this.onWindowScroll),this.resizeObserver=new ResizeObserver(this.onElementResize),this.resizeObserver.observe(this._el))}destroy(){window.removeEventListener("resize",this.onWindowResize),window.removeEventListener("scroll",this.onWindowScroll),this.resizeObserver&&this.resizeObserver.disconnect(),this._el&&this.resetTop()}};export{h as default}; | ||
//# sourceMappingURL=index.js.map |
import { ElementType } from "./types"; | ||
export declare const getElementHeight: (el: ElementType) => number; | ||
export declare const getScrollY: () => number; | ||
export declare const getWindowHeight: () => number; | ||
export declare const getElementHeight: (el?: ElementType | undefined) => number; |
{ | ||
"name": "cleversticky", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Enhanced \"position: sticky\" functionality", | ||
@@ -23,3 +23,4 @@ "main": "dist/index.js", | ||
"build-demo": "rimraf demo-build && parcel build ./demo/index.html -d demo-build", | ||
"ts-types": "tsc --emitDeclarationOnly" | ||
"ts-types": "tsc --emitDeclarationOnly", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -26,0 +27,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47
16132