gpt4 book ai didi

javascript - document.viewport.getHeight() 不准确?

转载 作者:行者123 更新时间:2023-11-29 16:30:02 25 4
gpt4 key购买 nike

关于Scriptaculous的Effect.Move演示可以参见 here :

<style type="text/css">
a#move_demo { background:#fa0000; color:#fff; padding:5px; border:1px solid #000; }
</style>

<div class="demo">
<a href="#" id="move_demo" onclick="new Effect.Move(this, { x: 60, y: -30 }); return
false;">Click me for a demo!</a>
</div>

对于包含该内容的单个页面,document.viewport.getHeight() 返回 32,而对于宽度,则可以。

为什么会出现这样的情况呢?难道不应该是视口(viewport)的高度,而不是文档顶部到底部的高度吗?

有解决办法吗?

最佳答案

事实证明,您需要一个正确的 DOCTYPE 才能使其正常工作,否则 Prototype 将处于“怪异模式”,这不会让 getheight() 按预期工作。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

关于javascript - document.viewport.getHeight() 不准确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/645642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com