Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery(window).height() doesn't work on mobile browsers

I have a full page slideshow using jQuery(window).height() and it works fine on most browsers, however I checked it out on my phone (Android Browser & Dolphin) and the slideshow just keeps growing endlessly, well beyond the height of the view-port. This is my code:

var height = jQuery(window).height();
jQuery('.slide').each(function(index, element) {
    if(height > 600) jQuery(this).height(height);
    else jQuery(this).height(600);
});
jQuery(window).on('resize orientationChanged', function() {
    jQuery('.slide').each(function(index, element) {
        if(height > 600) jQuery(this).height(height);
        else jQuery(this).height(600);
    });
});

Any ideas what could be causing it?

Thanks.

like image 366
Adam B Avatar asked Dec 30 '12 21:12

Adam B


Video Answer


1 Answers

so after 3 year of this question asked jquery window height still not working in mobile devices just replace jquery with javascript and it worked for me.

replace jquery

var bodyh = jQuery("body").height();
var windowh = jQuery(window).height();

with javascript

 var bodyh = document.body.clientHeight;
 var windowh = window.innerHeight;
like image 138
Shahid Chaudhary Avatar answered Oct 14 '22 05:10

Shahid Chaudhary