【问题标题】:Evaluate orientationEvent and setting a value?评估orientationEvent并设置一个值?
【发布时间】:2011-03-04 14:49:43
【问题描述】:

如果我有一个 onChange 函数在方向改变发生时触发,我如何在 onChange 中设置一个值来更新 jquery 选择器。例如:

  $(document).ready(function(){    
    var onChanged = function() {
            if(window.orientation == 90 || window.orientation == -90){
                image = '<img src="images/land_100.png">';
            }else{
                image = '<img src="images/port_100.png">';
            }
     }
        $(window).bind(orientationEvent, onChanged).bind('load', onChanged);
        $('#bgImage').html(image); //won't update image
   });

【问题讨论】:

    标签: jquery orientation screen-orientation device-orientation


    【解决方案1】:

    你需要把更新的图片放到onChanged函数里面,这样每次方向改变时,图片的HTML都会改变。

    $(document).ready(function(){   
    
       // The event for orientation change
       var onChanged = function() {
    
          // The orientation
          var orientation = window.orientation,
    
          // If landscape, then use "land" otherwise use "port"
          image = orientation == 90 || orientation == -90 ? "land" : "port";
    
          // Insert the image
          $('#bgImage').html('<img src="images/'+image+'_100.png">');
    
       };
    
       // Bind the orientation change event and bind onLoad
       $(window).bind(orientationEvent, onChanged).bind('load', onChanged);
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 2016-07-26
      • 2021-08-17
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多