Home

Thursday, June 11, 2015

jQuery Window Width Determined Initially and When Resized

jQuery(window).ready(function() {
    var wi = jQuery(window).width(); 
    jQuery("p.testp").text('Initial screen width is currently: ' + wi + 'px.');

    jQuery(window).resize(function() {
        var wi = jQuery(window).width();

        if (wi <= 480){
            jQuery("p.testp").text('Screen width is less than or equal to 480px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 767){
            jQuery("p.testp").text('Screen width is between 481px and 767px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 980){
            jQuery("p.testp").text('Screen width is between 768px and 980px. Width is currently: ' + wi + 'px.');           
            }
        else if (wi <= 1200){
            jQuery("p.testp").text('Screen width is between 981px and 1199px. Width is currently: ' + wi + 'px.');           
            }
        else {
            jQuery("p.testp").text('Screen width is greater than 1200px. Width is currently: ' + wi + 'px.');
//        jQuery().addClass();
            }
    });           
});

<p class="testp"></p>

Reference By :  http://www.surfingsuccess.com/jquery/window-width.html#.VXk5YPnPxNM

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth