how to get width of screen before every resize on page?

javascript, jquery, resize, responsive-design

Solution

In the `resize()` handler, update `oldwidth` with the new width as the very last line of the function.

$(document).ready(function () {
    var oldwidth = $(window).width();
    $(window).resize(function () {
        var nw = $(window).width();
        //compare new and old width      
        oldwidth = nw;
    });
});

Problem

I have this code ``` $(document).ready(function(){ var oldwidth= $(window).width(); $(window).resize(function(){ var nw= $(window).width(); //compare new and old width }); }); ``` The problem is the old width is only set during loading of document, new width changes during every resize. I want to get the width just before resizing, so I can check if user is decreasing width or increasing width of screen.

Original source