lhl 6ff0e96ad3 8-4-1 | há 1 ano atrás | |
---|---|---|
.. | ||
demo | há 1 ano atrás | |
dist | há 1 ano atrás | |
esm | há 1 ano atrás | |
CHANGELOG.md | há 1 ano atrás | |
LICENSE | há 1 ano atrás | |
README.md | há 1 ano atrás | |
index.d.ts | há 1 ano atrás | |
package.json | há 1 ano atrás |
This project is basically a modified version of sdecima/javascript-detect-element-resize including these changes:
ResizeObserver
first..css
file.$ npm i --save resize-detector
import { addListener, removeListener } from 'resize-detector'
// adding listener
addListener(elem, callback)
// removing listener
removeListener(elem, callback)
this
inside callback
function is the element whose size has been changed.
As resize-detector
is published in both ES Module & CommonJS format and when you use webpack to bundle your app, the ESM version will be imported. It is not transpiled by Babel or similar tools so you have to transpile it in your build process.
For webpack with babe-loader you need to add it to the include
field of the options:
// ...
{
test: /\.js$/,
loader: 'babel-loader',
include: [
// other stuff to be transpiled
// ...
path.resolve('node_modules/resize-detector')
]
}
// ...
If you are using other toolchain, just configure your bundler similarly so that resize-detector
will be transpiled during build process.
No.
Yes.
Scroll-based + Mutation-based.
Pros
Side effects
position: static
will become position: relative
.No.
No.
Scroll-based.
Pros
<object>
s.Side effects
position: static
will become position: relative
.Limitations
Yes.
Yes.
Use MutationObserver
to observe every mutation in a document. For IE9/10, use Mutation Events instead.
Pros
Limitations
:hover
.No.
No.
Listen to resize
events via hidden <iframe>
s.
Dead simple.
Side effects
position: static
will become position: relative
.Limitations
Yes.
Yes.
Long polling through requestAnimationFrame
or setTimeout
.
Dead simple.
Side effects
No.
No.
Either hidden <object>
s or scroll-based.
Two approaches available (Really, why?) with scroll-based approach being much faster than hidden <object>
s.
Side effects
position: static
will become position: relative
.Limitations