javascriptif-statementviewport-units

JS How to use relative units in a condition


I have a div, that is 15vh high. In javascript I sometimes change it's height to 20vh. My question is, How to make a condition, if "the div's height" == 15vh, do something? When I use jquery .css("height")the returned value is in pixels and .height() does the same. Because I'm learning, I'd appreciate as simple solution as possible, or a breaf explanation of what's happening.


Solution

  • $(window).height() will give you the value of 1vh in px.

    So you can make a condition if "the div's height" == 15 * $(window).height()