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);
精彩评论