jeudi 15 janvier 2015

"if windows.width less than" doesn't work

i have this code and i'm trying to make it work.


Basically, if the screen is less than 480px wide, is resizes the height of the #page div and centers it vertically. Else, if the width is wider, is just centers it vertically.



jQuery(document).ready(function(){
var wwidth = jQuery(window).width();
if (wwidth <= 480) {
function thirty_pc() {
var height = jQuery(window).innerHeight();
var thirtypc = ((95 * height) / 100) - 40;
var topmargin = (height - thirtypc - 40) / 2;
thirtypc = parseInt(thirtypc) + 'px';
topmargin = parseInt(topmargin) + 'px';
jQuery("#page").css('height',thirtypc);
jQuery("#page").css('margin-top',topmargin);
}

thirty_pc();
jQuery(window).bind('resize', thirty_pc);

} else {
function thirty_pc() {
var height = jQuery(window).innerHeight();
var pageheight = jQuery("#page").height()
var thirtypc = (height - pageheight - 60);
var topmargin = (thirtypc / 2);
thirtypc = parseInt(thirtypc) + 'px';
topmargin = parseInt(topmargin) + 'px';
jQuery("#page").css('margin-top',topmargin);
}

thirty_pc();
jQuery(window).bind('resize', thirty_pc);
}});


However, it doesn't fire when windows.width is less than 480px... cannot understand why.


Aucun commentaire:

Enregistrer un commentaire