且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定最大可能的DIV高度

更新时间:2023-02-10 21:24:33

这是你的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.