在onload上评估orientationEvent?

时间:2011-03-04 04:57:32

标签: jquery orientation screen-orientation device-orientation

我正在开发一个Web应用程序,它要求我根据orientationEvent更改内容。它到目前为止运作良好,在我改变方向时改变和设置内容。但是,我还需要orientationEvent来触发onLoad。这可能吗?

$(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);
});

1 个答案:

答案 0 :(得分:1)

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);