orientationchange에서 화면 너비를 계산해야합니다.Jquery/Javascript의 orientationchange 이벤트에서 Android에서 페이지 너비를 얻는 방법?
나는 이런 식으로 일을 해요 :
$(window).on('orientationchange', function(event){
$(this).panelWidth("orientationchange")
});
panelWidth: function (fromWhere) {
window.setTimeout(function() {
var $wrapWidth = $('div:jqmData(wrapper="true").ui-page-active').innerWidth();
console.log($wrapWidth);
},10);
});
이미 화면 폭을 계산하는 10ms의 지연을 사용하고 있지만, 안드로이드에 여전히 작동하지 않습니다 ...
내 화면입니다 320x480. 나가 초상화에서 시작하고 조경에 갈 경우 나는 320px를 얻는다. 나가 인물로 다시 변화 할 때, 나는 480px를 중심에두기 때문에, 방향이 실제로 변화하기 전에 너비는 항상 계산되는 것처럼 보인다.
가능한 경우 시간 제한을 늘리고 싶지 않습니다. 안드로이드가 화면을 "돌리는"것을 완료했을 때만 $ wrapWidth를 계산할 수있는 다른 방법이 있습니까?
도움 주셔서 감사합니다.
편집 :
JQuery와 모바일 sourceode에서 일부 정보 :
...as the actual screen resize takes place before or after the orientation
change event has been fired depending on implementation (eg android 2.3 is
before, iphone after). More testing is required to determine if a more reliable
method of determining the new screensize is possible when orientationchange
is fired. (eg, use media queries + element + opacity)
아. 나는 두 번째 해결 방법을 좋아한다. 아주 좋아! 이것을 지적 해 주셔서 감사합니다! – frequent
확인. 크로스 디바이스 (안드로이드는 물론)에서 작동하는 솔루션이 있습니다. 내 대답보기 – frequent