문제

I want something to happen when I resize my browser window, but every thing on the page must be loaded first. This doesn't work, but you get the picture:

$(window).resize(function(){
    $(window).load(function(){
        // do stuff
    });
});

How can I make this work?

도움이 되었습니까?

해결책

You need to attach the resize handler after the page has loaded, so reverse your event handlers:

$(window).load(function(){
    $(window).resize(function(){
        // do stuff
    });
});

다른 팁

I've recently had the same issue. Bind it both the load and resize event as below:

$(window).on('load resize', function () {
// your code
});

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top