편집 예를 들면, 나는 쉽게, 절대 위치 헤더를 사용하여 스크롤하기 전에를 숨기고 마무리 스크롤 (내가 지원하는 동일한 코드를 필요로 할 때 그것을 보여 발견 iOS4 및 Android). 내 목적을 위해 , 나는 touchstart
이벤트에 헤더를 숨기고, (/ 응답 성을 향상 깜빡임을 줄이기 위해 플러스 일부 타이머) touchend
또는 scroll
이벤트를 다시 보여줍니다. 그것은 깜박이지만 내가 발견 할 수있는 최상의 타협입니다. 하나는 touchmove
이벤트를 (jQuery를이 작업을 수행)를 사용하여 스크롤의 시작을 감지 할 수 있습니다,하지만 난 때문에 touchmove
나를 위해 잘 작동하지 않았다 발견 :
정기적으로 아이 패드가 스크롤하기 전에 다시 그리기를 할 실패 (즉, 스크롤을 시작하기 전에 top
이 변경된 경우에도 절대 머리글이 고정 된 상태로 유지됩니다.
입력 요소가 포커스를 얻으면 iPad는 요소를 자동 중심에 배치하지만 scrollstart 이벤트는 발생하지 않습니다 (입력이 단지 click
인 경우 터치 이동이 없기 때문에).iOS5를 고정 헤더에 구현
는
고정 절대 위치의 하이브리드 방식을 사용함으로써 개선 될 수있다 : 입력 포커스를 얻는다 iOS5를위한
코드는 document
요소에 DOMFocusOut
이벤트를 등록하고 다음 코드 같은 것을 할 것입니다. 한 요소가 포커스를 얻고 다른 요소가 포커스를 잃을 때 사이에 DOMFocusOut
이벤트가 발생할 수 있기 때문에 시간 초과가 필요합니다.
function document_DOMFocusOut() {
clearTimeout(touchBlurTimer);
touchBlurTimer = setTimeout(function() {
if (document.activeElement == document.body) {
handleKeyboardHide();
}
}.bind(this), 400);
}
내 고정 된 헤더 코드는 뭔가 같은 :
{
setup: function() {
observe(window, 'scroll', this, 'onWinScroll');
observe(document, 'touchstart', this, 'onTouchStart');
observe(document, 'touchend', this, 'onTouchEnd');
if (isMobile) {
observe(document, 'DOMFocusOut', this, 'docBlurTouch');
} else if (isIE) {
// see http://ajaxian.com/archives/fixing-loss-of-focus-on-ie for code to go into this.docBlurIe()
observe(document, 'focusout', this, 'docBlurIe');
} else {
observe(isFirefox ? document : window, 'blur', this, 'docBlur');
}
},
onWinScroll: function() {
clearTimeout(this.scrollTimer);
this.scrolling = false;
this.rehomeAll();
},
rehomeAll: function() {
if ((isIOS5 && this.scrolling) || isIOS4 || isAndroid) {
this.useAbsolutePositioning();
} else {
this.useFixedPositioning();
}
},
// Important side effect that this event registered on document on iOs. Without it event.touches.length is incorrect for any elements in the document using the touchstart event!!!
onTouchStart: function(event) {
clearTimeout(this.scrollTimer);
if (!this.scrolling && event.touches.length == 1) {
this.scrolling = true;
this.touchStartTime = inputOrOtherKeyboardShowingElement(event.target) ? 0 : (new Date).getTime();
// Needs to be in touchStart so happens before iPad automatic scrolling to input, also not reliable using touchMove (although jQuery touch uses touchMove to unreliably detect scrolling).
this.rehomeAll();
}
},
onTouchEnd: function(event) {
clearTimeout(this.scrollTimer);
if (this.scrolling && !event.touches.length) {
var touchedDuration = (new Date).getTime() - this.touchStartTime;
// Need delay so iPad can scroll to the input before we reshow the header.
var showQuick = this.touchStartTime && touchedDuration < 400;
this.scrollTimer = setTimeout(function() {
if (this.scrolling) {
this.scrolling = false;
this.rehomeAll();
}
}.bind(this), showQuick ? 0 : 400);
}
},
// ... more code
}
의 jQuery 모바일 scrollstart 및 scrollstop 이벤트 지원
var supportTouch = $.support.touch,
scrollEvent = "touchmove scroll",
touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
function triggerCustomEvent(obj, eventType, event) {
var originalType = event.type;
event.type = eventType;
$.event.handle.call(obj, event);
event.type = originalType;
}
// also handles scrollstop
$.event.special.scrollstart = {
enabled: true,
setup: function() {
var thisObject = this,
$this = $(thisObject),
scrolling,
timer;
function trigger(event, state) {
scrolling = state;
triggerCustomEvent(thisObject, scrolling ? "scrollstart" : "scrollstop", event);
}
// iPhone triggers scroll after a small delay; use touchmove instead
$this.bind(scrollEvent, function(event) {
if (!$.event.special.scrollstart.enabled) {
return;
}
if (!scrolling) {
trigger(event, true);
}
clearTimeout(timer);
timer = setTimeout(function() {
trigger(event, false);
}, 50);
});
}
};
가이, 나는이 아이폰 OS 버그 떠날 것입니다 판명를 지금은 문제지만 제안 사항이 유효하므로이 대답을 올바르게 표시 할 것입니다 – jas
jas, iOS 버그 발행 URL에 대한 링크를 제공 할 수 있습니까? – robocat
iOS6에서 수정 된 내용을 검토하지는 않았지만 하나 이상의 추가 버그가 추가되었습니다. http://igstudio.blogspot.com/2012/09/positionfixed-in-ios-6.html (나 또한 고정 div에 하드웨어 가속 합성을 강제하는 CSS 속성을 부여한 것으로 의심 될 수도 있습니다). – robocat