开发者

Evaluate orientationEvent at onload?

开发者 https://www.devze.com 2023-02-14 14:15 出处:网络
I\'m working on a web app and it requires me to alter content based on the orientationEvent. It\'s working well so far, changing and setting content as I change orientation.However, I need the orient开

I'm working on a web app and it requires me to alter content based on the orientationEvent. It's working well so far, changing and setting content as I change orientation. However, I need the orient开发者_Go百科ationEvent to also fire at onLoad. Is this possible?

$(document).ready(function(){
var onChanged = function() { //TODO: Need to learn a way to fire it at load time
        if(window.orientation == 90 || window.orientation == -90){
            $('#nav').html('<b> : LANDSCAPE : </b>');
        }else{
            $('#nav').html('<b> : PORTRAIT : </b>');
        }
        event.stopPropagation();
    }
 $(window).bind(orientationEvent, onChanged);
});


var onChanged = function() { //TODO: Need to learn a way to fire it at load time
        if(window.orientation == 90 || window.orientation == -90){
            $('#nav').html('<b> : LANDSCAPE : </b>');
        }else{
            $('#nav').html('<b> : PORTRAIT : </b>');
        }
        event.stopPropagation();
    }

$(document).ready(function(){
   $(window).bind(orientationEvent, onChanged);
}).bind('load', onChanged);
0

精彩评论

暂无评论...
验证码 换一张
取 消