Javascript run with certain resolution

Asked

Viewed 261 times

0

I have a javascript, and I need it to run only with resolutions under 700px.

Follow my code below:

$(document).ready(function(){
$('.menu').hide();

/* menu */
$('.menu').click(function(){
    $('.menu').slideToggle(200);
});

});

2 answers

1


You can use the object window screen. to catch the screen size. In it you can use the properties width and height to get the screen size.

Example:

document.getElementById("width").innerHTML = "Width: " + screen.width + "px";

document.getElementById("height").innerHTML = "Height: " + screen.height + "px";

if (screen.width > 700) {
  document.getElementById("resultado").innerHTML = "Width é maior que 700px.";
} else {
  document.getElementById("resultado").innerHTML = "Width é menor que 700px.";
}
<p id="width"></p>
<p id="height"></p>
<p id="resultado"></p>

0

Buddy, try to take his resolve and make a simple if.

$(document).ready(function(){
var screenH = window.screen.availHeight;
var screenW = window.screen.availWidth;

if(screenW<700){
    alert('run code here');
}
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.