- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
基于答案 from a previous question ,两者都指的是鼠标位置(x 和 y 坐标)。
我已经阅读了一篇关于 QuirksMode 的文章,但是我想我可能会遗漏一些东西。我将这两个图表放在一起以帮助我理解。我的分析正确吗?
现在将文档滚动 250px...
最佳答案
您的分析是正确的(而且这些图表非常好!)
但是关于您的其他帖子,它们提供的信息比必要的要多一些。
你只需要了解有文档和视口(viewport)。文档是静止的,视口(viewport)会随着您移动(并且有滚动偏移)。
原则上,您可以相对于其中任何一个放置对话窗口。让我们假设对话框是一个简单的分割元素:
<body>
<button id="save">Save</button>
<div id="dialog" style="position:absolute;">Are you sure?</div>
</body>
假设您希望在单击时相对于您的按钮定位该元素。您可以使用文档:
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = e.pageY + "px";
/*
pageY gives the position of the mouse relative to the
document, when this event occurred.
*/
};
</script>
或者您可以使用视口(viewport):
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = e.clientY + window.pageYOffset + "px";
/*
clientY gives the position of the mouse relative to
the viewport, when this event occurred. And pageYOffset
is the distance the user has scrolled.
*/
};
</script>
您甚至可以使用按钮本身。这样做的额外好处是无论用户点击的具体位置如何,都能为您提供一致的位置:
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = document.getElementById("save").offsetTop + "px";
/*
offsetTop gives the position of the button, relative to its nearest
positioned ancestor. If the element is deeply nested, you may need
to do additional calculations. (jQuery's "offset" method will do this
for you).
*/
};
</script>
要在使用 jQuery 的对话框类时应用最后一个方法,您可以简单地这样做:
<script>
$("#save").click(function(e) {
$("#dialog").dialog({
position: {
my: "top",
at: "bottom",
of: $("#save")
}
/*
See this: http://docs.jquery.com/UI/API/1.8/Position
*/
});
});
</script>
关于javascript - 我对 javascript 中鼠标位置的文档和视口(viewport)的理解是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7103649/
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始
我有一个 HTML 元素,宽 1000 像素,高 850 像素(它实际上是一个 iFrame,在 canvas 标签上包含一个 HTML5 游戏,但我希望这不会有影响)。 我希望元素在平板电脑上呈现,
我正在创建一个 2D 引擎,我想实现对接,所以我需要创建一个视口(viewport)并将屏幕渲染为纹理。 为了渲染视口(viewport),我将帧缓冲区保存到一个 FrameBufferObject
大多数移动页面都提供元视口(viewport)尺寸,例如 出于 iphone 向后兼容的原因,这将在宽度上模拟 320px... 但是当我通过 javascript 检查时 window.screen
我有一个客户提供的宽度为 1440 像素的网站。客户要求我使用以下方法将视口(viewport)设置为 1440 像素对于桌面浏览器,小于 1440 像素的屏幕不显示滚动条。 它确实适用于移动设备、i
我刚刚读了一篇 nice article on viewport这给我留下了几个关于移动设备上的视觉视口(viewport)与布局视口(viewport)的问题。 the width and the
layout viewport和visual viewport的解释可以找到here . 我已阅读 here和 here那个应该使用 如果想针对移动设备优化网页。 我想了解这对横向模式下的 ipho
我想用javascript获取视口(viewport)宽度。但不是常见的虚拟视口(viewport)。我需要逻辑硬件视口(viewport),在我的情况下,它不是设置视口(viewport)元标记的选
我有一个 menu 元素,如果 menu 元素变得在视口(viewport)之外,我想固定到浏览器视口(viewport)的顶部由于滚动。从概念上讲,我的网页看起来类似于下面的示例 HTML,其中菜单
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
我只包含了“main”的 HTML 代码,因为这是我希望能够通过媒体查询控制的部分。我希望内容只能在小于 480 像素的视口(viewport)上查看,但浏览器似乎隐藏了所有视口(viewport)尺
我不知道如何描述这个,所以最好的办法是链接一个例子:http://www.pascalvangemert.nl/#/profile 无论这个人对侧边栏菜单做了什么都很棒,我很想复制它。我试过检查,但我
我遇到了一页末尾有空白的问题。据我所知,没有元素占据空间。仅当视口(viewport)设置为特定宽度时才会出现该空间。例如,它出现在宽度 940 和 400 左右,但不是 550 或非常宽。 起初我以
iPhone/iPad 等移动设备的视觉视口(viewport)和布局视口(viewport)有什么区别? 网上查了很多资料,还是不清楚。 最佳答案 视觉视口(viewport)是当前显示在屏幕上的页
我正在使用这个元标记来设置移动浏览器上的视口(viewport)大小: 和这个 css 以确保较大的图像不会导致在较小的视口(viewport)上滚动: img { max-width: 95%;
这是针对平板电脑浏览器的,它使用相对于视口(viewport)宽度/高度的尺寸。为简单起见,假设横向。 我在一个全屏容器中有两个 div,就像提供的图像一样。他们有 position:absolute
我在 opengl 中创建了一个迷宫,并且正在尝试创建一个小 map 。为此,我想到在视口(viewport)内创建一个视口(viewport)。我有三种方法,一种用于创建墙壁,另一种用于创建地板,另
所以我有 2 个屏幕:一个级别选择屏幕,使用分辨率为 720 x 405 的 FitViewport,然后是一个游戏屏幕,使用分辨率为 480 x 270 的 FillViewport,按每米像素数
无论视口(viewport)的宽度如何,我都有一个图像幻灯片,我试图将其置于视口(viewport)的中心。如果视口(viewport)比图像宽,使用 margin: auto; 很容易实现,但是,当
我有一个元素,该元素具有从屏幕边缘底部弹出并循环向下弹出(虽然不是完全向下)的动画。下面的代码对此非常有用。但是,有一个问题。当浏览器全屏显示时,百分比占旧视口(viewport)大小而不是新视口(v
我是一名优秀的程序员,十分优秀!