Moving a window
- moveBy() method
Use moveBy() to move a window either horizontally, vertically, or both, by the specified amount in pixels. Note that a negative parameter value causes the window to be moved in the opposite direction. Here are a couple of examples:
Example #1: Move to the Left!
<form> <input type="button" onClick="window.moveBy(5,0)" value="Move to the right"> </form>
Example #2: Shake window
Let's briefly explain the cause of the earthquake in the second example:
moveTo(), as the method name implies, moves a window to the specified coordinates on the screen. Two common uses of it is to move a newly opened window to the upper left corner of the screen, and to the dead center. Let's see an example of each!
Example #3: Move to upper-left corner
Example #4: Move to center
The center coordinates of the screen in the second example is calculated by determining the screen's dimensions, dividing that by 2, and subtracting half of either the window's width/height from it. In other words, in order to center a window, it's dimensions have to be known before hand...
Let's move on, shall we?