In jQuery, is it poss开发者_如何学JAVAible to somehow "bind" an action to both the ready
function and a resize
event? I'm trying to add/remove classes on resize and I want the initial class state to be there on ready.
The easiest way to do this is to trigger the resize
event immediately after binding it:
$(document).ready(function() {
$(window).resize(function() {
// code to run on resize
}).resize(); // trigger resize handlers
});
function onresize()
{
// do your stuff here
}
// called on "init"
onresize();
// called when window is resized
$(window).resize(function(){ onresize(); });
精彩评论