Native event listener polyfill to capture element size changes
https://konglingwen94.github.io/element-resize-event-polyfill/dist/demo.html
npm install element-resize-event-polyfill --save-dev
Example in es6
import 'element-resize-event-polyfill'
const elm = document.getElementById('#elm')
elm.addEventListener('resize', handler)
Example in browser
<head>
<script src="element-resize-event-polyfill.umd.min.js"></script>
</head>
<body>
<div id="elm">My size changes can be captured</div>
</body>
<script>
const elm=document.getElementById("elm")
// case one
elm.addEventListener("resize",function(e){
// Your logic
})
// case two
elm.onresize=function(e){
// Your logic
}
</script>
Example in vue
<template>
<div v-on:resize="handlerResize"></div>
</template>
<script>
export default {
methods:{
handlerResize(e){
// Your code
}
}
}
</script>
Example in cdn
<script src="https://unpkg.com/element-resize-event-polyfill@1.0.5/dist/element-resize-event-polyfill.umd.min.js"></script>
<div class="container" id="container">
</div>
<script>
const elm = document.getElementById('container')
elm.addEventListener('resize', function(e) {
// Your code
})
</script>