Pages

Friday, November 29, 2013

Javascript-Fire event on resolution change

In the era of responsive websites sometimes it is needed to fire an event on change of resolution.

My designer was stuck in one such scenario and we sorted the same out as follows


 <script>  
 $(document).ready(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);  
 }());  
 $(window).bind('resolutionchange', heightchanges)  
 function heightchanges(){  
 /*Your code on resolution change event here*/
 }  
 });  
 </script>  

No comments:

Post a Comment