2

오리엔테이션 변경이 발생했을 때 onChange 함수가 실행되면 jQuery 선택기를 업데이트 할 onChange 값을 어떻게 설정합니까? 예를 들면 다음과 같습니다.orientationEvent를 평가하고 값을 설정 하시겠습니까?

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

답변

8

업데이트 할 때마다 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); 

}); 
관련 문제