I was checking the size of body
for $(window).resize
but I realize that when starting the page initially the size is right but it does not apply to classes
. Follow the Code:
jQuery.noConflict()(function($) {
"use strict";
$(document).ready(function() { // Inicializar app quando o documento esta pronto
$(window).on('load', function() {
$('.preloader').delay(350).fadeOut(); // Page Preloading
$('body').hide().delay(350).show(); // Force Chrome to repaint fonts
checkSize();
$(window).resize(checkSize);
});
});
function checkSize() {
var width = $(window).width();
if (width >= 320 || width <= 480) {
$('.teste').addClass('celular').removeClass('desktop phablet').html('Celular: '+width);
} else if (width >= 481 || width <= 767) {
$('.teste').addClass('phablet').removeClass('desktop celular').html('Phablet: '+width);
} else {
$('.teste').addClass('desktop').removeClass('celular phablet').html('Desktop: '+width);
}
}
}(jQuery)); // Passar em (jQuery):
#body {
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divid="body">
<div class="teste"></div>
</div>