문제

I have the max-height of an element as 65vh. I need to convert it to pixels in my JavaScript to see whether an image can fit there or if I need to shrink/crop it. (am doing win8 App development).

Will this work?

100 vh = screen.height therefore 65vh in pixels is screen.height *0.65

도움이 되었습니까?

해결책

Not necessarily screen.height * 0.65, but viewport.height * 0.65. Even though a Windows 8 app will always have the same height, regardless of the snapped state, this is an important difference in browser-based applications.

In JavaScript:

document.documentElement.clientHeight * 0.65;

If you're using jQuery, you can do:

$(window).height() * 0.65;

다른 팁

When I use $("div").height(); it actually returns the value in pixels.

Check this fiddle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top