D
D
DonTraffic2020-04-28 07:43:23
JavaScript
DonTraffic, 2020-04-28 07:43:23

How to take out the value of X and check if it is greater than 1200?

There is a code that displays the value of the custom screen extension when executed.

var x = 0;

window.addEventListener("resize", function() {
  document.getElementById('widthInner').innerHTML = window.innerWidth;
  x = window.innerWidth;
}, false);

<span id="width">0</span>
You need to set the screen resolution values ​​for the X variable and check if it is greater than 1200. If it is greater, then execute alert('complete').
When I tried to do this, the value just didn't show up.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2020-04-28
@DonTraffic

window.addEventListener("resize", function() {
  x = window.innerWidth;
  return x > 1200 ? alert('complete') : false;
}, false);

P
profesor08, 2020-04-28
@profesor08

https://www.npmjs.com/package/js-media-query
Subscribe to the event and do your thing.
You can see in the source code what and where it comes from.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question