1.1.0 • Published 5 years ago

libj-window-scrollbar v1.1.0

Weekly downloads
3
License
ISC
Repository
-
Last release
5 years ago

libj-window-scrollbar

Part of libj tools

This is used to remove window's scrollbar temporarily and restore it again

JQuery is a dependency

Usage (npm)

npm install libj-window-scrollbar
import { windowScrollbar } from 'libj-window-scrollbar'
windowScrollbar.remove()
/* removes window's scrollbar */

windowScrollbar.restore()
/* restores window's scrollbar to its previous position */

Test

  • Run this in a separate command line to start node server
node server.js
  • Run one of the following to re-create bundles
npm run dev
npm run dev:watch

Source

var key = "-libj-window-scroll-position";
window[key] = window[key] || -1;
class WindowScrollBar {
    remove() {
        window[key] = $(document).scrollTop();
        $("body")
            .css("overflow", "hidden")
            .css("height", "100%");
        $("html")
            .css("overflow", "hidden")
            .css("height", "100%");
    }
    restore() {
        $("body").css("overflow", "visible");
        $("html").css("overflow", "visible");
        $(document).scrollTop(window[key]);
    }
}
var windowScrollbar = new WindowScrollBar();
export { windowScrollbar };