Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
body-scroll-freezer
Advanced tools
Readme
Dependency-free JS module to freeze body scroll when opening modal box.
Useful for modal, sliding-panel and lightbox interfaces.
<1kb minified.
Many other alternatives to this module listen to both mousewheel
and DOMMouseScroll
events in order to get some information from the DOM, which usually includes: Element.scrollTop
, event.deltaY
, Element.scrollHeight
or Element.clientHeight
. Check this StackOverflow answer as an example.
The problem is that most of those DOM operations (.scrollTop
and .scrollHeight
, for example) are expensive because they force layout/reflow. For more info on scrolling performance check out this article.
So, to avoid all that, body-scroll-freezer just assigns overflow: hidden;
and padding-right: [scrollWidth]px;
to the <body>
.
The overflow
avoids vertical move on the background when users are scrolling within the modal box. The padding-right
prevents horizontal jumps when hiding/showing the scrollbar.
// If no AMD/CommonJS: window.bodyScrollFreezer;
var bodyScroll = require('body-scroll-freezer');
1. Init to calculate scroll bar width.
// Note: declaring variable to store init() return is optional.
var scrollWidth = bodyScroll.init();
2. Turn scroll freeze ON when closing modal. Example:
document.querySelector('.modal-open').addEventListener('click', function() {
// Logic to show modal goes here
bodyScroll.freeze();
}, false);
3. Turn scroll freeze OFF when closing modal. Example:
document.querySelector('.modal-close').addEventListener('click', function() {
// Logic to hide modal goes here
bodyScroll.unfreeze();
}, false);
FAQs
Dependency-free JS module to freeze body scroll when opening modal box
The npm package body-scroll-freezer receives a total of 139 weekly downloads. As such, body-scroll-freezer popularity was classified as not popular.
We found that body-scroll-freezer 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.