I'm trying to trigger an event on resize of window, it seems like it does not work.
$(window).resize(function(){
_.debounce(function(){
console.log("hello");
}, 100);
})
It's actually shown in their lodash documentation as an example, lodash#debounce:
$(window).on('resize', _.debounce(function() {
console.log('resized!');
}, 100));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
Vanilla JS in case:
window.onresize = _.debounce(() => {
console.log('resized!')
}, 100)
EDIT: Actually probably better to use event listener instead:
window.addEventListener('resize', _.debounce(() => {
console.log('resized!')
}, 100)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With