2010-03-11 2 views
1

그리고 전체 화면의 '높이'1/2로 설정하십시오.'div'요소를 화면 (폭)으로 설정하는 방법, 아이폰이 방향을 바꿀 때 전체 화면 (너비)

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" manifest="/m?manifest=1"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no, width=device-width"> 

</head> 
<body > 
<div></div> 
<style type="text/css"> 
div{ 
background:red; 
} 
</style> 
<script src="jquery-1.4.2.js" type="text/javascript"></script> 
<script type="text/javascript"> 


</script> 
</body> 
</html> 

답변

1

내가 CSS와 자바 스크립트 (jQuery를 사용)의 조합으로 할 것 :

이 내 코드입니다. CSS를위한 자바 스크립트

 updateOrientation : function() { 
      var orientation = window.orientation; 

      switch (orientation) { 

       // If we're horizontal 
       case 90: 
       case -90: 

       // Set orient to landscape 
       $(body).addClass("landscape"); 
       break; 

       // If we're vertical 
       default: 

       // Set orient to portrait 
       $(body).addClass("portrait"); 
       break; 
      } 

     } 

에 대한

: 이것은 단지 기본적인 윤곽이

body{ 
    height: 240px; 
} 

/* Reposition on orientation change */ 
body.landscape{ 
    height: 160px; 
} 

, 당신이 맞는 볼을 조정

+0

하지만, 사업부 전체 화면되지 않습니다 (의 너비) – zjm1126

+0

방향 이벤트의 이벤트를 잡는 방법 (변경시). 감사합니다. – zjm1126

+0

window.onorientationchange = updateOrientation – tzenes

관련 문제