1

I would need some help regarding media queries applied to javascript. Is it possible to resize an object starting from the javascript code with a screen width other than the "default" one?

Example: I have a button, and when I click on it, it opens me a div with a height of 600px. the screen here is 1600px wide. can I make sure that when the screen is for example at 1000px wide, the div that is shown has a height of 800px? And if it is possible, can this happen several times, that is, that the condition does not disappear once this div is closed and then repoened?

Internetto
  • 11
  • 1

1 Answers1

0

the easiest way to do this is probably with css media queries

@media (max-width: 1000px) {
   div {
      height: 800px;
   }
}
JDawwgy
  • 888
  • 2
  • 18
  • I can't do what you say because here I put the height of the div when it is closed and only in the javascript file I go to define the height of the open div. – Internetto May 27 '22 at 19:25
  • Html code:

    ...
    – Internetto May 27 '22 at 19:25
  • Javascript code: var open = false; function functionA(){ if(!open){ document.getElementById("div1").style.height="800px"; } else{ document.getElementById("div1").style.height="600px"; } } – Internetto May 27 '22 at 19:25