{"id":16978704,"url":"https://github.com/srph/scrollbar-compensate","last_synced_at":"2025-11-06T22:30:24.244Z","repository":{"id":75646720,"uuid":"66841075","full_name":"srph/scrollbar-compensate","owner":"srph","description":"A hack to compensate for scrollbar for modals","archived":false,"fork":false,"pushed_at":"2017-12-23T04:23:34.000Z","size":9,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T11:11:55.962Z","etag":null,"topics":["dialog","modal","scrollbar"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srph.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-29T12:18:10.000Z","updated_at":"2018-04-23T16:19:28.000Z","dependencies_parsed_at":"2023-04-29T18:01:45.074Z","dependency_job_id":null,"html_url":"https://github.com/srph/scrollbar-compensate","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"310684280ca03e64623fbfc691189d93235ff79d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srph%2Fscrollbar-compensate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srph%2Fscrollbar-compensate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srph%2Fscrollbar-compensate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srph%2Fscrollbar-compensate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srph","download_url":"https://codeload.github.com/srph/scrollbar-compensate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239513383,"owners_count":19651322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dialog","modal","scrollbar"],"created_at":"2024-10-14T01:44:02.953Z","updated_at":"2025-11-06T22:30:24.156Z","avatar_url":"https://github.com/srph.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scrollbar-compensate [![npm version](http://img.shields.io/npm/v/scrollbar-compensate.svg?style=flat)](https://npmjs.org/package/scrollbar-compensate)\n```\nnpm i scrollbar-compensate\n```\nA hack to compensate for scrollbar size for modals\n\n## Problem\nUsually, you would set `overflow: hidden` to body when the modal mounts. However, this causes a weird adjustment to the layout (because the scrollbar disappears). This mostly affects Windows/Linux users, and some OSX users that use a mouse (because it forces the scrollbar to appear).\n\nAs an example, compare [Semantic UI's Modal](http://semantic-ui.com/modules/modal.html) and [TWBS' Modal](http://getbootstrap.com/javascript/#modals). TWBS solved this by adding a `padding-right` to the `body` when the modal mounts.\n\n## What It Does\nIt adds an inline-style that adds a `padding-right` to the provided selectors. It appends the following to `head`:\n\n```html\n\u003cstyle\u003e.my-selector, .my-selector-2 .my-nested-selector { padding-right: 15px; }\u003c/style\u003e\n```\n\nTake note that the `15px` value here may vary depending on your scrollbar width. Typically, OS X has this set to `15px`.\n\n## Usage\n`compensate(selectors)` \u0026mdash; This module only exposes a single function that accepts an array of elements as *an* argument. Usually, you pass class names here that are added to the body when a modal mounts.\n\n```js\nvar compensate = require('scrollbar-compensate');\n\ndocument.addEventListener('DOMContentLoaded', function() {\n  compensate(['.modal-open', '.overlay-enabled .global-nav']);\n});\n```\n\n**Note** — If you're wondering why it's necessary to run `compensate` when the document loads: We're using the [`scrollbar-size`](https://www.npmjs.com/package/scrollbar-size) library internally which needs to be called after the document is ready.\n\n## Examples\n[jquery-modal](https://github.com/srph/jquery-modal) is using this library.\n\n## Alternatives\n[no-scroll](https://github.com/davidtheclark/no-scroll) also solves this problem, however covers more than scrollbar compensation.\n\nUse this library only if you want the scrollbar compensation library. Otherwise, check the alternatives.\n\n## Note\nThis library isn't available in UMD because I don't really need it at the moment. Please send a PR or submit an issue if you'd like it to be implemented. Moreover, no tests yet.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrph%2Fscrollbar-compensate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrph%2Fscrollbar-compensate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrph%2Fscrollbar-compensate/lists"}