jQuery的高度返回px不vh [英] jquery height returning px not vh

查看:140
本文介绍了jQuery的高度返回px不vh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Soo,我正在处理html编辑器,并将vh值设置为div.但是,当我尝试使用$(id).height();$(id).css("height");时,它总是返回px值,而不是vh.这应该不成问题,但是我打算让用户选择是否要使用px或vh. 那么,是让jquery(或js)告诉我设置的是哪种类型的高度值的另一种方法? 我的问题不是关于将数据从px转换为%,而是是否有可能弄清将高度设置为css中的哪种类型.在这种情况下,如果将其定义为px或vh

Soo, Im working on an html-editor and setting vh values to div's. But when I try to use $(id).height(); or $(id).css("height"); it is always returning px value and not the vh. This should not be a problem, but I was planing on making is to a user could choose if he wished to use px or vh. So is it another way to get jquery(or js) to tell me what type of height value that is set? My question is not about converting data from px to %, but if it is possible to figure out what type of messurement the height is set as in css. In this case if it was defined as px or vh

推荐答案

您将始终获得以像素为单位的高度或宽度.您将必须手动将其转换为vhvw

You will always get height or width in pixels. You will have to manually convert it to vh or vw value

这是先前的问题: https://stackoverflow.com/a/28295133/1548301

1px =(100/document.documentElement.clientWidth)vw
例如- 如果你的 然后视口为500px宽(按定义等于100vw)

1px = (100 / document.documentElement.clientWidth)vw
e.g. — If your viewport was 500px wide (equals by definition to 100vw) then

1px =(100/500)= 0.2vw

1px = (100 / 500) = 0.2vw

这篇关于jQuery的高度返回px不vh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆