如何使用 JavaScript 移动窗口在计算机屏幕上的位置?
我记得看过一个谷歌地图混搭/音乐视频,它在屏幕上创建、调整大小和移动窗口。使用什么 JavaScript 方法来执行此操作?
I remember seeing a google maps mashup / music video that created, resized, and moved windows on the screen. What javascript methods are used to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道这有多可靠,但是要将窗口相对于当前位置移动,您可以这样做:
http://www.w3schools.com/jsref/met_win_moveby.asp
将窗口移动到屏幕的特定部分:
http://www.w3schools.com/jsref/met_win_moveto.asp
由@Dan Herbert提供:
I don't know how reliable this is, but to move the window relative to it's current position you can do this:
http://www.w3schools.com/jsref/met_win_moveby.asp
To move the window to a certain part of the screen:
http://www.w3schools.com/jsref/met_win_moveto.asp
Courtesy of @Dan Herbert:
通过快速谷歌搜索:移动窗口
您正在寻找 Window.moveBy 和 window. moveTo
我也记得那个视频,你选择你的家乡什么的?我非常喜欢那个。
From a quick google search: Moving windows
You're looking for Window.moveBy and window.moveTo
I remember that video too, you select your hometown and whatnot? I quite liked that.
您可以通过更改显示对象的上边距和左边距(它们一起构成其左上角的坐标)来移动显示对象的位置。如果您知道目标位置的绝对坐标,则可以更改边距,对象将移动到该位置。
如果您不知道绝对目标位置,但只知道两个相对增量(即,将窗口向上移动 5 个像素,向右移动 10 个像素),您可以读取对象的上边距和左边距,将它们增加适当的距离,然后从中设置边距。
边距是对象样式的一部分,因此您可以这样说:
对于定位的对象。
You move a displayed object's position by changing its top and left margins, which, together, are the coordinates of its top left corner. If you know the absolute coordinates of the target position, you can change the margins and the object will move to that spot.
If you don't know the absolute target position, but only know two relative deltas (i.e., move the window up 5 pixels and right 10 pixels), you can read the object's top and left margins, increment those by the appropriate distances, and set the margins from that.
Margins are part of the style of the object, so you'd say something like:
for a positioned object.
由于您的链接包含锚点“#”,因此当您单击链接时,会将页面移回顶部。尝试将 href 替换为以下内容:
这将阻止 href 中的任何内容执行。
Since your links contain anchors, "#", when you click on the links it will move the page back to the top. Try replacing the href with something like:
This will prevent anything within the href from executing.