horizontal and vertical orientation event
After I posted a
fix suggestion I implemented a event to facilitate my work. When the orientation is horizontal or vertical.
Should be nice if these events come implemented in jquery mobile
My implementations to this:
after including the jquery script, I added..
- $(function() {
- var setOrientation = function() {
- if (window.orientation === undefined) { // desktop
- return;
- }
-
- if (Math.abs(window.orientation) == 90) { // horizontal
- $(document).triggerHandler('onHorizontalOrientation');
- }
- else { // vertical
- $(document).triggerHandler('onVerticalOrientation'); // meu evento
- }
- };
- var orientationEvent = "onorientationchange" in window ? "orientationchange" : "resize";
- window.addEventListener(orientationEvent, setOrientation, false);
- setOrientation();
- });
and my script general file I added..
- $(document).bind('onHorizontalOrientation', function(){ alert('horizontal'); });
- $(document).bind('onVerticalOrientation', function(){ alert('vertical'); });