It's cross-browser compatible:
- Opera Mobile 12
- Safari Mobile
$ component install pazguille/viewport
Also, you can use it without components.
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');
Now, starts to use it!
viewport.height // Returns the current height of the viewport. (Read below the API)
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.
Returns 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.
Updates the viewport dimension, viewport positions and orientation.
scroll: emitted when the viewport are scrolled.
resize: emitted when the dimensions of the viewport changes.
bottom: emitted when the viewport position is the bottom.
top: emitted when the viewport position is the top.
- E-mail: email@example.com
- 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.