Home › Forums › JavaScript › reload jquery functions on ipad orientation change › Re: reload jquery functions on ipad orientation change
February 15, 2012 at 10:16 am
#96734
Member
I normally put all the stuff that needs doing on a resize or reload in one function and then bind and call that function at load, resize and orient. You can always split. It up into separate resize and orient functions and call both at load but only one at resize etc.
function myOrientResizeFunction(){
all resize/orientation stuff to do in here
}
//bind to resize
$(window).resize( function() {
myOrientResizeFunction()
});
//if you need to call it at page load to resize elements etc.
$(window).load( function() {
myOrientResizeFunction()
});
//check for the orientation event and bind accordingly
if (window.DeviceOrientationEvent) {
window.addEventListener('orientationchange', myOrientResizeFunction, false);
}