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.
size-sensor
Advanced tools
The size-sensor npm package is used to detect changes in the size of an HTML element. It can be useful for responsive design, dynamic content adjustments, and other scenarios where you need to react to changes in element dimensions.
Detecting size changes
This feature allows you to bind a callback function to an HTML element that will be called whenever the size of the element changes.
const { bind, clear } = require('size-sensor');
const element = document.getElementById('myElement');
bind(element, () => {
console.log('Element size changed!');
});
Unbinding size change detection
This feature allows you to unbind the size change detection from an HTML element, stopping the callback from being called when the element's size changes.
const { bind, clear } = require('size-sensor');
const element = document.getElementById('myElement');
const sensor = bind(element, () => {
console.log('Element size changed!');
});
// Later, if you want to stop detecting size changes
clear(sensor);
The resize-observer-polyfill package provides a polyfill for the ResizeObserver API, which is a native browser API for detecting changes to the size of an element. It offers similar functionality to size-sensor but is based on a standard API that is becoming widely supported in modern browsers.
The element-resize-detector package is another library for detecting changes in the size of an HTML element. It offers more customization options and different strategies for detecting size changes, such as object-based and scroll-based detection.
DOM element size sensor which will callback when the element size changed.
DOM 元素尺寸监听器,当元素尺寸变化的时候,将会触发回调函数!
npm i --save size-sensor
Then import it.
import { bind, clear } from 'size-sensor';
or import it by script
in HTML, then get sizeSensor
on window.
<script src="https://unpkg.com/size-sensor/dist/size-sensor.min.js"></script>
import { bind, clear } from 'size-sensor';
// bind the event on element, will get the `unbind` function
const unbind1 = bind(document.querySelector('.container'), element => {
// do what you want to to.
});
const unbind2 = bind(document.querySelector('.container'), element => {
// do what you want to to.
});
// if you want to cancel bind event.
unbind1();
import { bind, clear } from 'size-sensor';
/*
* // bind the resize event.
* const unbind1 = bind(...);
* const unbind2 = bind(...);
* ...
*/
// you can cancel all the event of element.
clear(element);
There is only 2 API:
Bind the resize trigger function on element. The function will return unbind
function.
Clear all the object and resize event on element.
The size sensor strategies include:
ResizeObserver
: use resizeObserver to observe element's size.object
: use object document's resize event.If ResizeObserver
exists, use it, else use object
as default.
Online demo click here. Used By:
ISC@hustcc.
FAQs
DOM element size sensor which will callback when size changed.
We found that size-sensor 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.