Open a new window and move it 250px relative to its current position:
function openWin() {
myWindow = window.open('', '', 'width=400, height=400');
}
function moveWin() {
myWindow.moveBy(250, 250);
}
Try it Yourself »
More examples below.
The moveBy()
method moves a window a number of pixels relative to its current coordinates.
window.moveBy(
x, y)
Parameter | Description |
x | Required. A positive or negative number. The number of pixels to move the window horizontally. |
y | Required. A positive or negative number. The number of pixels to move the window vertically. |
NONE |
Using moveBy() together with moveTo():
function moveWinTo() {
myWindow.moveTo(150, 150);
}
function moveWinBy() {
myWindow.moveBy(75, 75);
}
Try it Yourself »
moveBy()
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!