Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in jquery if screen resolution changes?

How can I make it so that each time when user changes the screen resolution size [not the browser window], the page perform a function?

like image 520
Safran Ali Avatar asked Dec 20 '11 12:12

Safran Ali


People also ask

What is my screen resolution Javascript?

Answer: Use the window. screen Object You can simply use the width and height property of the window. screen object to get the resolution of the screen (i.e. width and height of the screen).


1 Answers

Ok, so you're using jQuery. So let's make a custom event for it.

(function () {     var width = screen.width,         height = screen.height;     setInterval(function () {         if (screen.width !== width || screen.height !== height) {             width = screen.width;             height = screen.height;             $(window).trigger('resolutionchange');         }     }, 50); }()); 

Now $(window).bind('resolutionchange', fn) should do what you want.

like image 79
Nathan MacInnes Avatar answered Oct 11 '22 16:10

Nathan MacInnes