The blend of debounced
resize
event withorientationchange
flavor. See the demo.
window.addEventListener('resize:end', function(event) {
// Your callback, e.g.
console.log(event.type);
}, false);
The resize:end
(and resizeend
) event is dispatched in two cases:
It’s the cure for those window.onresize
skips that occur every pixel as long as you keep resizing your browser’s window. Details matter. performance++
, too.
Switching from portrait mode into landscape (and vice versa) triggers resize:end
. If rotating a device doesn’t alter its viewport dimensions (e.g. rotating it upside down), the event isn’t dispatched, because there’s simply no need to.
Tested in the following browsers:
- Safari 6+
- Chrome 20+
- Firefox 14+
- Opera 12+
- Internet Explorer 9+
- Mobile Safari on iOS 6+
Any suggestions are welcome. You can also find me on Twitter: I’m @porada.
Distributed under MIT license.