javascript - 如何使用 javascript 移动窗口在计算机屏幕上的位置?

标签 javascript jquery methods window

我记得看过一个谷歌地图混搭/音乐视频,它可以在屏幕上创建、调整大小和移动窗口。使用哪些 javascript 方法来执行此操作?

最佳答案

我不知道这有多可靠,但是要相对于当前位置移动窗口,您可以这样做:

window.moveBy(250, 250); //moves 250px to the left and 250px down

http://www.w3schools.com/jsref/met_win_moveby.asp

将窗口移动到屏幕的某个部分:

window.moveTo(0, 0); //moves to the top left corner of the screen (primary)

http://www.w3schools.com/jsref/met_win_moveto.asp

由@Dan Herbert 提供:

It should probably be noted that window.moveTo(0,0) will move to the top left corner of the primary screen. For people with multiple monitors you can also send negative coordinates to position on another monitor. You can check for a second monitor to move to with screen.availLeft. If it's negative, you can move a window that far onto the second monitor.

关于javascript - 如何使用 javascript 移动窗口在计算机屏幕上的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7841849/

相关文章:

javascript - 如何将 JSON 对象重新持久化为具有关联方法的对象?

javascript - 如何将变量从 EJS 页面传递到另一个 EJS 页面

javascript - 为什么 iframe 不能设置其父级的 location.hash?

jquery - jquery ajax 发送到 MVC Controller 时不断收到 400(错误请求)

Java - 方法选择算法

java - 窗口显示图形而不是空白

设置后 JavaScript 调用 init 函数

javascript - tr 的背景颜色不会使用 jquery 改变

类中的Python调用方法

php - 发送路由 POST 参数的问题