I'm trying to manually fire the $(window).resize() method on page load. I created a function to center a div element vertically and horizontally on the page
$(window).resize(function(){
$('.pagecentered').css({
position: 'absolute',
left: ($(window).width() - $('.pagecentered').outerWidth())/2,
top: ($(window).height() - $('.pagecentered').outerHeight())/2
});
});
After this function I call
$(window).resize();
to fire the resize() event manually.
Unfortunately it doesn't work. On reload the div is not centered as expected. If I resize the browser window the div element is centered it only isn't fired on page load.
Is there any way to solve this? I'm using Chrome 27.0.1453.116 m (latest version atm) and JQuery 1.10.2
You need to use trigger
: $(window).trigger('resize');
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