Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@egstad/detect-scroll
Advanced tools
A performant and lightweight ES6 module for detecting scroll activity (direction + location) for X and/or Y axis
A performant and lightweight (~1.6kb) ES6 module for detecting scroll activity (direction + location) for X and/or Y axis
The default scroll event listener is amazing and all, but isn't exactly the most usable tool out of the box. It's all, "Hey look, a user scrolled!". And I'm like "Great! But like, in what direction and where did they stop?". And then it's all like, "IDFK, how about you do some math and figure it out".
In short, this little library adds a handful of helpful CustomEvent
's which make scroll detection a little more insightful.
View Example
Note: Open your console to preview debug mode
npm install @egstad/detect-scroll
detectScroll
.element
you'd like to monitor the scroll activity of. Can be a string selector (ie: '.scroll-container'
), or any valid HTMLElement
. In our case, we'll use the window
.destroy()
will remove all event listeners.import detectScroll from '@egstad/detect-scroll'
// setup instance & events
const instance = new detectScroll(window, {
events: {
scrollUp: foo(),
scrollDown: bar(),
},
})
// if/when you want to destroy the instance and events
instance.destroy()
Another way to get up and running with this library is to handle the events yourself. This option registers and dispatches all Events, but you'll have to add/remove the event listeners yourself.
import detectScroll from '@egstad/detect-scroll'
// setup instance
const instance = new detectScroll(window)
// setup events
window.addEventListener('scrollUp', foo)
window.addEventListener('scrollDown', bar)
// if/when you want to destroy all events
window.removeEventListener('scrollUp', foo)
window.removeEventListener('scrollDown', bar)
const instance = new detectScroll(window, {
vertical: true,
horizontal: true,
passiveMode: true,
debugMode: false,
events: undefined,
})
Optional Properties | Default Value | Description |
---|---|---|
vertical | true | Registers & Dispatches y-axis activity |
horizontal | true | Registers & Dispatches x-axis activity |
passiveMode | true | Determines if scroll event is passive or not |
debugMode | false | Logs events in console as they dispatch |
events | undefined | Event overrides (see Events section for more) |
Scroll events are dispatched using CustomEvent
's. Here's a gorgeous list of all 10.
If you would like to a specific selection of them, check out this example.
Custom Event Name | Description |
---|---|
scrollStart | Fired when scrolling begins |
scrollStop | Fired when scrolling ends |
scrollX | Fired every time x position updates |
scrollY | Fired every time y position updates |
scrollUp | Fired when scrolling up |
scrollDown | Fired when scrolling down |
scrollLeft | Fired when scrolling left |
scrollRight | Fired when scrolling right |
scrollMinX | Fired when the left-most part of el/window is reached |
scrollMaxX | Fired when the right-most part of el/window is reached |
scrollMinY | Fired when top of element/window is reached |
scrollMaxY | Fired when bottom of element/window is reached |
const foo = (ev) => {
console.log(ev.type)
}
const instance = new detectScroll(window, {
events: {
// exclude any of these and the event's won't be registered or fired
scrollStart: foo,
scrollStop: foo,
scrollX: foo,
scrollY: foo,
scrollUp: foo,
scrollDown: foo,
scrollLeft: foo,
scrollRight: foo,
scrollMinX: foo,
scrollMaxX: foo,
scrollMinY: foo,
scrollMaxY: foo,
},
})
FAQs
A performant and lightweight ES6 module for detecting scroll activity (direction + location) for X and/or Y axis
We found that @egstad/detect-scroll 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.