我想提出一個簡單的刷卡畫廊,在這裏我只需要它來隱藏的默認瀏覽器滾動條,並通過圖像刷卡容器寬度。我爲滑動邏輯使用jQuery和TouchSwipe插件。到目前爲止,我已經寫了這個代碼:https://jsfiddle.net/drbj6zk8/5/。我已經加入容器中(通過獲取計算(div.swipe - div.swipe,包裝)和刷卡不應該去這些境外的iOS忽略了組隊,探索畫廊
$(函數(){
var currentTranslation = 0;
var lastDistance = 0;
var translationDelta = 0;
var containerLengthArr = $('div.swipe-slide');
var containerLength = 0;
var containerBorder = 0;
$("#test5").swipe({
swipeStatus: swipe2,
allowPageScroll: "horizontal"
});
/*TODO*/
$.each(containerLengthArr, function(e) {
containerLength += ($(this).width() + 10);
})
$('.swipe-wrapper').width(containerLength + 5);
containerBorder = $('.swipe').width() - $('.swipe-wrapper').width();
console.log(containerBorder);
//Swipe handlers
function swipe2(event, phase, direction, distance) {
var check = $(this).children('.swipe-slide');
if (phase == "end") {
translationDelta = 0;
} else {
translationDelta = lastDistance - distance;
}
/*Check direction*/
if (direction == "right") {
currentTranslation -= translationDelta;
} else if (direction == "left") {
currentTranslation += translationDelta;
}
var distance2 = 0;
/*Limit slider to wrapper lenghth*/
if (currentTranslation > 0) {
distance2 = "translateX(" + 0 + "px)";
currentTranslation = 0;
}
else if (currentTranslation < containerBorder) {
distance2 = "translateX(" + containerBorder + "px)";
currentTranslation = containerBorder;
}
else {
distance2 = "translateX(" + currentTranslation + "px)";
}
check.css('transform', distance2);
lastDistance = distance;
console.log(currentTranslation);
}
});
。當然,一切都運行在桌面瀏覽器和Android設備很好,但我碰到了與iOS設備的問題。我們絕對沒有跨不同設備(iPhone 5,iPhone 6,iPad的)行爲的一致性。在所有他們中我變得不同,更重要的是破碎的行爲(或者滑塊看起來不一樣,更重要的是,sw。超出設定的邊界)。
有誰知道我錯過了什麼或者是否有一些具體的要求,這在iOS工作?