Is there any way with jQuery or JavaScript to trigger a function when the user ends to resize the browser window?
In other terms:
- Can I detect mouse up event when user is resizing the browser window? Otherwise:
- Can I detect when a window resize operation is finished?
I’m currently only able to trigger an event when the user start to resize the window with jQuery
You can use
.resize()to get every time the width/height actually changes, like this:You can view a working demo here, it takes the new height/width values and updates them in the page for you to see. Remember the event doesn’t really start or end, it just “happens” when a resize occurs…there’s nothing to say another one won’t happen.
Edit: By comments it seems you want something like a “on-end” event, the solution you found does this, with a few exceptions (you can’t distinguish between a mouse-up and a pause in a cross-browser way, the same for an end vs a pause). You can create that event though, to make it a bit cleaner, like this:
You could have this is a base file somewhere, whatever you want to do…then you can bind to that new
resizeEndevent you’re triggering, like this:You can see a working demo of this approach here