Javascript:计算DIV的高度减去像素 [英] Javascript: Calculate height of DIV minus pixels

查看:104
本文介绍了Javascript:计算DIV的高度减去像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在寻找一个javascript来为我做一个数学计算。我正在寻找能够读取整个窗口高度(不是屏幕尺寸)的东西,从该值减去100px,然后输出到(比方说,一个样式值)。是这样的可能吗?

I'm currently looking for a javascript to do a math calculation for me. I'm looking for something that will read the height of an entire window (not screen size), minus 100px from that value, and then output in to, lets say, a style value. Is something like this possible?

预先感谢!

推荐答案

div,你可以使用属性innerHeight,如下所示:

To calculate the height of a div, you can use the property innerHeight, something like:

var height = document.getElementById('somediv').innerHeight;

然后,您可以对此变量进行所需的计算,稍后使用如下形式:

Then, you can do the calculations you need on this variable, and use later in something like:

document.getElementById('otherdiv').style.height = height + 'px';

这篇关于Javascript:计算DIV的高度减去像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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