1

我正在开发一个网络应用程序,它需要我根据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);
});
4

1 回答 1

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);
于 2011-03-04T05:01:47.970 回答