Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery - screen size condition

0 votes
39 views
added Aug 24 in jQuery by LC Marshal Lieutenant (14,570 points)
if ($(window).width() < 768) {
   alert('This is tab screen size');
}
else {
   alert('This is desktop size');
}

 

2 Responses

0 votes
responded Aug 29 by LC Marshal Lieutenant (14,570 points)
var alterClass = function() {
  if (($(window).width() <= 480)){
           // if its smaller, do this
          $(".sidebar").addClass('modal');
          $(".sidebar").addClass('fade');
  }else{
          // Otherwise, reverse the classes
          $(".sidebar").removeClass('modal');
          $(".sidebar").removeClass('fade');
  }
}

$(window).resize(function(){
  alterClass();
});
//use function when page loads
alterClass();

 

0 votes
responded Oct 26 by LC Marshal Lieutenant (14,570 points)
var loginHeader = $('.head-container a.login');
$(loginHeader).html('Log in to Support Centre');

//mobile screen condition
if ($(window).width() < 500) {
 $(loginHeader).html('Login');
}
else {
 $(loginHeader).html('Log in to Support Centre');
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...