Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@xobotyi/scrollbar-width
Advanced tools
The @xobotyi/scrollbar-width package is a small, dependency-free utility for measuring the width of the browser's scrollbar. It is useful for accurately calculating layout dimensions when scrollbars might affect the overall width of containers, particularly in responsive designs or complex layouts.
Get scrollbar width
This feature allows you to measure the width of the scrollbar. The function returns the width in pixels as a number. If the scrollbar is not present, it returns 0. This is useful for adjusting layout dimensions dynamically based on the presence of scrollbars.
import scrollbarWidth from '@xobotyi/scrollbar-width';
const width = scrollbarWidth();
console.log(`Scrollbar width is ${width}px`);
Re-measure scrollbar width
This feature forces a re-measurement of the scrollbar width. This can be useful when the document or window has changed significantly (e.g., after dynamically loading content) and you need to ensure the measurement is still accurate.
import { scrollbarWidth } from '@xobotyi/scrollbar-width';
const width = scrollbarWidth(true);
console.log(`Re-measured scrollbar width is ${width}px`);
The 'dom-helpers' package offers a variety of utilities for managing DOM elements, including a function to measure scrollbar width. Compared to @xobotyi/scrollbar-width, dom-helpers provides a broader range of DOM-related utilities, which makes it more versatile but also larger in size.
Similar to @xobotyi/scrollbar-width, 'scrollbar-size' is a focused utility for measuring the size of the scrollbar. It provides a similar functionality but differs in API design and implementation details. Users might choose one over the other based on specific project compatibility or personal preference in API style.
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()
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 returnundefined
in case being called before the DOM is ready.
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.
FAQs
A tool to get browser's scrollbars width.
We found that @xobotyi/scrollbar-width demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.