【问题标题】:Evaluate orientationEvent at onload?在加载时评估orientationEvent?
【发布时间】:2011-03-04 04:57:32
【问题描述】:

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

【问题讨论】:

    标签: jquery orientation screen-orientation device-orientation


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2012-11-21
      • 2011-06-26
      • 2021-09-25
      • 2018-08-20
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      相关资源
      最近更新 更多