を使用してhttp://jsbin.com/xujofoze/4/editとビューを使って、私はそれが簡単に、絶対的な位置付けヘッダを使用し、スクロールする前にそれを隠し、それを表示することが判明iOS4とAndroid)。私の目的のために
、私はtouchstart
イベントにヘッダを隠し、および(ちらつきを軽減/応答性を改善するために、プラスいくつかのタイマー)touchend
またはscroll
イベントに再びそれを示しています。それは点滅しますが、私が見つけることができる最高の妥協です。一つはtouchmove
イベントを(jQueryのがこれを行う)を使用して、スクロールの開始を検出することができますが、私はのでtouchmove
が私のためにも動作しませんでした:
は定期的にiPadがスクロールする前に再描画を行うには失敗した(つまり、スクロールを開始する前にtop
が変更されていても、絶対ヘッダーがスタックされたままになります)。
入力要素がフォーカスを取得したとき、iPadは要素の自動中心化を行いますが、scrollstartイベントは発生しません(入力がclick
の場合はtouchmoveがないため)。
iOS5を上に固定されたヘッダを実装
を固定し、絶対位置のハイブリッドアプローチを使用することによって改善することができる:入力フォーカスを取得するまで
キーボードが(例えば、キーボード非表示キーを使用して)閉じているときを検出するためのコードdocument
要素にDOMFocusOut
イベントを登録し、次のコードのようなものを行うことです。ある要素がフォーカスを取得してから別の要素がフォーカスを失うまでに、DOMFocusOut
イベントが発生する可能性があるため、タイムアウトが必要です。
function document_DOMFocusOut() {
clearTimeout(touchBlurTimer);
touchBlurTimer = setTimeout(function() {
if (document.activeElement == document.body) {
handleKeyboardHide();
}
}.bind(this), 400);
}
のように私の固定ヘッダコードが何かをされた:jQueryのモバイルがscrollstartとscrollstopイベントをサポート
{
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
}
:
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);
});
}
};
、これはiOSのバグで判明、私はこれを去ることになります今のところ問題はありますが、あなたの提案は有効ですので、私はこの回答に正しいとマークします – jas
jas、それはiOSのバグの問題のURLへのリンクを与えることは可能ですか? – robocat
私はiOS6で修正されたものを見ていませんが、少なくとも1つの追加のバグが追加されています:http://igstudio.blogspot.com/2012/09/positionfixed-in-ios-6.html固定divにハードウェアアクセラレーションによる合成を強制するCSSプロパティを与えると疑われる場合もあります)。 – robocat