jQuery window on resize

Run code on resize window:


$(window).resize(function () {

    $('.log').prepend('<div>' + $(window).width() + '</div>');  // code on resize window

});

Run code on resize window with 100 milliseconds interval:


$(window).resize(function () {

    var resizeTimer = null;

    if (resizeTimer) clearTimeout(resizeTimer);

    resizeTimer = setTimeout(function () {

        $('.log').prepend('<div>' + $(window).width() + '</div>'); // code on resize window

    }, 100); // adding 100 milliseconds interval for avoiding jumps

});

Leave a Comment