Coder Social home page Coder Social logo

trendingtechnology / react-scrollbar-size Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shawnmcknight/react-scrollbar-size

0.0 1.0 0.0 12.63 MB

React hook to calculate the size of browser scrollbars.

License: MIT License

JavaScript 23.14% TypeScript 73.57% HTML 2.20% CSS 1.10%

react-scrollbar-size's Introduction

React-Scrollbar-Size

React-Scrollbar-Size is a React hook designed to calculate the size of the user agent's horizontal and vertical scrollbars. It will also detect when the size of the scrollbars change, such as when the user agent's zoom factor changes.

npm package npm downloads CircleCI Code Climate Code Style Code style Dependabot Status Dependencies PeerDependencies DevDependencies Percentage of issues still open License Contributor Covenant Star on Github

Installation

React-Scrollbar-Size is available as an npm package:

$ npm install react-scrollbar-size

Usage

The useScrollbarSize custom hook returns an object with two properties:

Name Description
width The current width of the vertical scrollbar
height The current height of the horizontal scrollbar

Examples

To see a live example, follow these instructions.

TypeScript

import React, { CSSProperties, FunctionComponent } from 'react';
import useScrollbarSize from 'react-scrollbar-size';

const styles: CSSProperties = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo: FunctionComponent = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};

JavaScript

import React from 'react';
import useScrollbarSize from 'react-scrollbar-size';

const styles = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};

License

This project is licensed under the terms of the MIT license.

react-scrollbar-size's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar legneato avatar shawnmcknight avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.