确定最大可能的DIV高度 [英] Determine Maximum Possible DIV Height

查看:156
本文介绍了确定最大可能的DIV高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定一个DIV可以设置并保持每个浏览器中可见的最大高度推荐的方式?这似乎不是在任何地方记录,并具有高度的实现特定

Is there a recommended way to determine the maximum height that a DIV can be set and remain visible per browser? This doesn't appear to be documented anywhere and is highly implementation specific.

例如,请参见下面的测试脚本:

For example, see the following test script:

http://jsfiddle.net/NP5Pa/2/

这是一个简单的测试来发现你可以之前的元素对应的 clientHeight 设置一个DIV风格height属性的最高值变为0,您可以通过点击此确认查找最大,然后递增1的发现高度和单击设置高度。

This is a simple test to find the maximum value you can set a DIV style height attribute before the corresponding clientHeight of the element becomes 0. You can confirm this by clicking "Find Max" then incrementing the found height by 1 and clicking "Set Height".

一些例子(Win7的/ 64):

Some examples (Win7/64):

Chrome (14.0) :    134,217,726 px
Safari (5.1)  :    134,217,726 px
IE (9.0)      :     10,737,418 px
FF (7.0.1)    :     17,895,697 px

这并不奇怪WebKit的产生相同的结果,我想 - 更令人惊讶的是IE和FF是如此不同。

It's not surprising the WebKit produces the same result, I guess - more surprising that IE and FF are so different.

有没有更好的办法?而你在32位系统中得到不同的结果?

Is there a better way? And do you get different results in 32bit systems?

- 编辑:更新了小提琴停在百亿(和那里更快)的歌剧。这是一个很大的像素。

推荐答案

这是你的code,修改为使用二进制搜索(所以它的更快)。

This is your code, modified to use binary search (so it's much quicker).

http://jsfiddle.net/thai/zkuGv/4/

它开始于1个像素和倍增其大小,直到它碰到的最大(我用2 53 ,它是一种可以存储在JavaScript中而不丧失precision和将最大整数使二进制搜索电瓶车),或在div崩溃为零像素。

It begins at 1 pixel and doubling its size until the it hits the maximum (I use 253, which is the biggest integer that can be stored in JavaScript without losing precision and would make the binary search buggy), or the div collapses to zero pixel.

假设我们设定的股利大小的 ^ h 的和消失,那么最大尺寸之间必须的 ^ h 的/ 2和的 ^ h 的。从那里,我们的二进制搜索了高度的 ^ h 的,这并不使当设置为高股利消失的 ^ h 的,但消失时设置为 ^ h 的+ 1。

Suppose we set the div to size h and it disappears, then the maximum size must be between h/2 and h. We binary search from there for a height h that does not make the div disappear when set to height h, but disappears when set to h+1.

然后,我们可以来歌剧院结论:2147483583像素

Then we can come to a conclusion for Opera: 2147483583 pixels.

这篇关于确定最大可能的DIV高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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