JavaScript window.moveBy() Method
You are Here:
JavaScript window.moveBy() Method
The window.moveBy()
method moves the current window by a specified amount.
Note: Unlike window.moveTo(), this method moves the window to an relative to its current location.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<button onclick="myOpen()">Open Window</button>
<button onclick="myMoveBy()">MoveBy Window</button>
<script>
var myWindow;
function myOpen(){
myWindow = window.open("", "myWindow", "width=400, height=200");
}
function myMoveBy(){
myWindow.moveBy(40, 40);
myWindow.focus();
}
</script>
</body>
</html>
Syntax
window.moveBy(x, y)
Parameter Values
Value | Type | Explanation |
---|---|---|
x | Required | Specifies the horizontal coordinate to be moved by. |
y | Required | Specifies the vertical coordinate to be moved by. |
moveBy() vs moveTo()
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<button onclick="myOpen()">Open the Window</button>
<button onclick="myMoveTo()">MoveTo the Window</button>
<button onclick="myMoveBy()">MoveBy the Window</button>
<script>
var myWindow;
function myOpen(){
myWindow = window.open("", "myWindow", "width=400, height=200");
}
function myMoveTo(){
myWindow.moveTo(200, 100);
myWindow.focus();
}
function myMoveBy(){
myWindow.moveBy(40, 40);
myWindow.focus();
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.