Package detail

@xobotyi/scrollbar-width

xobotyi8mMIT1.9.5

A tool to get browser's scrollbars width.

scrollbar, width, native, browser

readme

@xobotyi/scrollbar-width

A tool to get browser's scrollbars width.

Build status NPM version NPM weekly downloads License Types definition Codacy Code Grade Tests LOC

× LIVE EXAMPLE ×


❤️Please consider starring this project to show your love and support.🙌

Installation

npm install @xobotyi/scrollbar-width
# or via yarn
yarn add @xobotyi/scrollbar-width

INSTALLATION NOTE:
This lib is written in TypeScript and delivered with both, transpiled and untranspiled ES versions:

  • main field of package.json is pointing to transpiled ES5-compatible version with CJS modules resolution;
  • module field is pointing to transpiled ES5-compatible version with ES modules resolution;
  • esnext field is pointing to the ESnext version with ES modules resolution;

OR
you can add it directly to your site via the <script /> with help of UNPKG:

<script src="https://unpkg.com/@xobotyi/scrollbar-width/dist/index.min.js"/>

After that you will be able to use the function as xobotyi.scrollbarWidth()

Usage

import { scrollbarWidth } from '@xobotyi/scrollbar-width';

scrollbarWidth(); // for most browsers will return 17 and 0 for SSR environment
// or undefined if to call it too early [read below]

This function caches the value to avoid increased resources usage. In case you want to get re-calculated value - pass true as first call parameter.

NOTE:
Function will return undefined in case being called before the DOM is ready.

One more clarification

This function has inner cache due to scrollbars width is not intended to be changed since initial call, but it can in case you toggle the device emulation.
If you need function to recalculate the width call it with true parameter and get new value or set scrollbarWidth.__cache to undefined and next call will return the fresh value.

Related projects

  • react-scrollbars-custom — The best React custom scrollbars component. Allows you to customise scrollbars as you like it, crossbrowser!
  • zoom-level — A comprehensive cross-browser package that allow you to determine page's and element's zoom level.
  • @xobotyi/should-reverse-rtl-scroll — A tool detecting if RTL scroll value should be negative.

changelog

1.9.5 (2020-03-25)

Bug Fixes

1.9.4 (2020-03-02)

Bug Fixes

  • lint: rename interface to pass linting; (a81601b)

1.9.3 (2020-02-24)

Bug Fixes

1.9.2 (2020-02-24)

Bug Fixes

  • add clarification about the cache as promised in issue #2; (944436f)

1.9.1 (2020-02-24)

Bug Fixes

  • adjusting document check for SSR (bd68002)

1.9.0 (2020-02-16)

Bug Fixes

  • added blank spaces after headings; (99da435)
  • lint-staged commands been using the tslint; (72810b9)

Features

  • terser now minifies all the code via rollup plugin; (3596475)

1.8.2 (2020-01-30)

Bug Fixes

  • tweak the travis build (build missing in dist). (77b4db3)

1.8.1 (2020-01-30)

Bug Fixes

  • make only dist directory appear in package. (adf19e6)

1.8.0 (2020-01-27)

Features

1.7.0 (2020-01-27)

Features

  • add weekly downloads badge; (59647de)
  • add weekly downloads badge; (da4a506)

1.6.1 (2020-01-27)

Bug Fixes

  • add root files to the linting process; (48c7e3c)

1.6.0 (2020-01-27)

Bug Fixes

  • TS config now does not conflicts with rollup (564d523)
  • tweak eslint config and fix the code; (456d726)

Features

  • get rid of .lock file - not needed here. (d5415e2)
  • Replace tslint with eslint (e4f29a2)

1.5.0 (2019-12-09)

Features

  • Add extra check of DOM readiness. (0bf89ef)

1.4.1 (2019-11-19)

Bug Fixes

  • coverage: Fix codacy coverage push; (b1545af)

1.4.0 (2019-11-19)

Bug Fixes

  • tests: Linux detection fix; (be38927)
  • FireFox on linux have SBW of width 16 (8d10f9b)

Features

  • modify travis config to push coverage and release the version only if everything is successful. (5deec11)

1.3.0 (2019-11-19)

Bug Fixes

  • reconfigure travis to perform tests and push coverage to the codacy; (cfc5c76)

Features

  • add tests (7d920cc)
  • Added codacy badges (coverage and grade) (aa723f7)

1.2.4 (2019-11-19)

Bug Fixes

  • newline after NOTE: in README.md (a2cfc39)

1.2.3 (2019-11-19)

Bug Fixes

  • newline after NOTE: in README.md (646153c)

1.2.2 (2019-11-19)

Bug Fixes

  • shorten the description; (dc6945a)

1.2.1 (2019-11-19)

Bug Fixes

  • Mention that in SSR environment it will return 0; (0562ef8)
  • Strictly require true to recalculate the width; (d25db0b)

1.2.0 (2019-11-19)

Features

  • Add access: public in package.json; (e373d9e)

1.1.1 (2019-11-19)

Bug Fixes

  • add github plugin to verify stage (55eb00d)

1.1.0 (2019-11-18)

Bug Fixes

  • remove npm cache from travis config; (1fab1e9)

Features

  • Live example version added to README.md; (d571839)
  • Readme's header now centered; (f9761d6)

1.0.0 (2019-11-18)

Bug Fixes

  • try to fix semantic release error; (bce4aa5)
  • umd version now exports function as xobotyi.scrollbarWidth; (f5ea7b1)

Features