简体   繁体   中英

Fire jQuery script onLoad and window resize

Here is where I'm at:

onResize = (function($) {
//Do stuff 
});
$(document).ready(onResize);
$(window).bind('resize', onResize);

The script calculates the width of it's containing div and then lays out a gallery accordingly. It runs onload correctly (no matter the window width ) but doesn't seem to fire on resize. The issue? Creates layout problems with my media Queries.

您的代码可在Chrome中正常运行。

Justin W Hall, I tried this in my chrome console:

onResize = (function($) { console.log('resized') });
    console.log('resized')
});
$(document).ready(onResize);
$(window).resize(onResize);

and it worked just fine.

ps. If you run this code, you'll notice that onResize function fires two times (showing 2 'resized' messages) when you resize the window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM