Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  82] [ 6]  / answers: 1 / hits: 53069  / 10 Years ago, tue, february 3, 2015, 12:00:00

I want to convert px to vw in JavaScript, how can I do it?



I've been looking for it, but I haven't found anything.



So,




1px → ? vw




Thanks.


More From » jquery

 Answers
12

1px = (100vw / [document.documentElement.clientWidth] px)



e.g. — If your viewport was 500px wide (equals by definition to 100vw) then



1px = (100vw / 500px) = 0.2vw



I used .clientWidth to exclude any scrollbar from computation


[#67975] Saturday, January 31, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeniferjaliyahf

Total Points: 650
Total Questions: 104
Total Answers: 86

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;