UNPKG

futura.js

Version:

A small JavaScript library for common tasks such as Carousel, Exception, Animation handler and more...

2 lines (1 loc) 628 B
let stiky = import Exception from "./Exception.js"; export default class Sticky{/** * @param elt * @param level */constructor(options = {elt : '',class : null, callback : null}) { if (options.elt === '') return new Exception('Element options is empty'); this.options = options; this.run();} run(){ let z = this.options, y = z.class.split(' ');window.addEventListener('scroll',(e) => {window.scrollY >= z.elt.getClientRects()[0].height ? y.forEach((e) => z.elt.classList.add(e)) || (z.callback ? z.callback() : false) : y.forEach((e) => z.elt.classList.remove(e)) ;})}}window.fJs = window.fJs ?? {};window.fJs.Sticky = Sticky;