jquery - Javascript mobile device width check and class remove -


i need remove classes site if device width under 1200 px (because of mobile view).

i tried use javascript, method worked fine:

$(window).resize(function(){ var current_width = $(window).width(); if(current_width < 1200)   $('a').removeclass("expand");   $( ".effects clearfix" ).remove();   $( ".overlay" ).remove();   $('#removeimg').removeclass('img').addclass('imgmobile');});  

but problem is, works if resize window. if open site using smartphone (android 4.3, chrome) script not work.

i tried write code failed:

function checkwidth() { var width = (window.innerwidth > 0) ? window.innerwidth : screen.width;     if (window.innerwidth < 1200)  {         $('#removeimg').removeclass('img').addclass('imgmobile');          }     if (window.innerwidth < 1200) {         $( ".effects clearfix" ).remove();         }     if (window.innerwidth < 1200) {         $( ".overlay" ).remove();         }     if (window.innerwidth < 1200) {         $('a').removeclass("expand");       } 

how can check device width , set these classes under 1200 px? (i tried modify/set initial values/ css media queries unfortunately still need remove classes :( )

thank idea.

you had placed code inside resize function, that's it's working on resize of window. call in once in ready function , once in resize too.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -