Javascript clientHeight和替代品 [英] Javascript clientHeight and alternatives

查看:99
本文介绍了Javascript clientHeight和替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试修改幻灯片中的< div>的Javascript函数。该脚本需要您定义div的高度,因此它在动态填充的< div>中是无用的。我在javascript中的clientHeight属性上找到了一些文本,但是它看起来不支持将显示设置为none的< div>(这是用于滑动div的方法)。这是有道理的,因为在客户端窗口中的div的高度是什么。



基本上我想知道什么其他的方法,你都知道,或者如果有一种方法



哦,这里是函数I 'm using:

  function getDivHeight(objName){
return boxHeight = document.getElementById(objName).clientHeight;
}


解决方案

它的可见性隐藏,它的显示阻止和测量。但是,一些现代浏览器会在这么短的时间内更新页面布局,你会得到一个讨厌的闪烁。解决这个问题的最简单方法是将元素放置在一个绝对定位的容器中,并将溢出设置为隐藏。


I am currently trying to modify a Javascript function that "slides in" a <div>. The script as it is requires you to define the height of the div, so it is mostly useless in dynamically filled <div>s. I found some text on the clientHeight property in javascript, but it would appear that it doesn't support <div>s with display set to none (which is the method used to slide the div in). That makes sense, as the height of that div in the client window is nothing.

Basically I was wondering what other methods you all know of, or if there's a way to get around the clientHeight = 0 when display: none.

Thanks!

Oh, and here's the function I'm using:

function getDivHeight(objName) {
    return boxHeight = document.getElementById(objName).clientHeight;
}

解决方案

A simple solution is to set it's visibility to "hidden" and it's display to "block" and measure it. However, some modern browsers will manage to update the page layout during this short time and you will get a nasty flicker. The easiest way to overcome this is to place the element in an absolutely positioned container with overflow set to "hidden".

这篇关于Javascript clientHeight和替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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