Solved: jquery check if screen size

The main problem with using jquery to check if the screen size is appropriate is that it can be inaccurate.

 is mobile

var isMobile = false; //initiate as false
// device detection
if(/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo||midp||mmp||netfront||opera m(ob|in)i||palm( os)?||phone||p(ixi|re)/8.0.+mobile.+firefox/i.test(navigator.userAgent)){ 
    isMobile = true;
}

This code is checking if the device is a mobile device or not. It starts by setting isMobile to false. Then, it uses a regular expression to check the user agent string of the navigator. If it finds a match, then it sets isMobile to true.

Screen properties in jQuery

There are a few properties that you can use to control how your screen looks in jQuery.

width and height: These properties set the width and height of the screen, in pixels.

orientation: You can use this property to specify whether the screen is portrait or landscape mode.

display: This property specifies whether the screen should be displayed as a full-screen window or not.

What is jQuery

jQuery is a JavaScript library that helps you create dynamic, responsive websites. It includes features for handling events, animating elements, and creating Ajax interactions.

Related posts:

Leave a Comment