It's cross-broswer compatible:
- Opera Mobile 12
- Safari Mobile
$ component install pazguille/viewport
First, add the following meta viewport:
<meta name="viewport" content="width=device-width,initial-scale=1.0">
Then, initialize the Viewport:
var Viewport = require('viewport'), vp = new Viewport();
Returns the current
width of viewport (in pixels).
Returns the current
height of viewport (in pixels).
Calculates/updates the dimensions (
height) of viewport (in pixels).
top of viewport.
right of viewport.
bottom of viewport.
left of viewport.
Calculates/updates the viewport position.
Returns vertical scroll position of viewport.
Returns horizontal scroll position of viewport.
Calculates/updates the scroll positions (
scrollX) of viewport.
Rertuns the device orientation:
Calculates/updates the device
Gets the position of the mouse cursor in screen coordinates. Returns an object with the following properties:
posY: y coordinate of the mouse pointer.
posX: x coordinate of the mouse pointer.
Device size is static and doesn't change when the page is resized. Returns an object with size of device (
Calculate if an element is completely located in the viewport. Returns boolean.
Calculates if an element is visible in the viewport. Returns boolean.
Upadtes the viewport dimension, viewport positions and orietation.
scroll: emited when the viewport are scrolled.
resize: emited when the dimensions of the viewport changes.
bottom: emited when the viewport position is the bottom.
top: emited when the viewport position is the top.
- E-mail: firstname.lastname@example.org
- Twitter: @pazguille
- Web: http://pazguille.me
The MIT License
Copyright (c) 2012 @pazguille
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.