跳转到主要内容

Window: moveBy() method

{{APIRef("CSSOM view API")}}

The moveBy() method of the {{domxref("Window")}}Window interface moves the current window by a specified amount.

[!NOTE]NOTE: This function moves the window relative to its current location. In contrast, {{domxref("window.moveTo()")}} moves the window to an absolute location.

Syntax

moveBy(deltaX, deltaY)

Parameters

  • deltaX
    • : The number of pixels to move the window horizontally. Positive values are to the right, while negative values are to the left.
  • deltaY
    • : The number of pixels to move the window vertically. Positive values are down, while negative values are up.

Return value

None ({{jsxref("undefined")}}undefined).

Examples

This example moves the window 10 pixels to the right and 10 pixels up.

function budge() {
  moveBy(10, -10);
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

As of Firefox 7, websites can no longer move a browser window in the following cases:

  1. You can't move a window or tab that wasn't created by {{domxref("Window.open()")}}.
  2. You can't move a window or tab when it's in a window with more than one tab.

[!NOTE]NOTE: This function might not move the window synchronously. In some environments (like Wayland, or mobile) it might not move the window at all. Currently there's no way to listen to a move event, see CSS Working Group issue #7693.

See also