jQuery resize function doesn't work on page load

后端 未结 5 1669
情话喂你
情话喂你 2020-11-28 14:05

How do I get this function to not only run on window resize but also on initial page load?

$(window).resize(function() {
...  
});
5条回答
  •  清酒与你
    2020-11-28 14:25

    Another approach, you can simply setup a handler, and spoof a resize event yourself:

    // Bind resize event handler through some form or fashion
    $(window).resize(function(){
      alert('Resized!');
    });
    
    // Trigger/spoof a 'resize' event manually
    $(window).trigger('resize');
    

提交回复
热议问题