gpt4 book ai didi

Javascript 平滑滚动 iPad

转载 作者:行者123 更新时间:2023-12-03 10:04:57 25 4
gpt4 key购买 nike

我使用此代码,
在 ipad 中滚动溢出 div(隐藏),并且预期它不平滑,有什么办法可以使它平滑滚动?

function initMobileScroll(ele) {
var mobileScrollArea = document.getElementById(ele);

mobileScrollArea.addEventListener('touchstart', function(event){
touchstart (event);
});

mobileScrollArea.addEventListener('touchmove', function(event){
touchmove (event);
});

// let’s set the starting point when someone first touches
function touchstart (e) {
startY = e.touches[0].pageY;
startX = e.touches[0].pageX;
}

// calls repeatedly while the user’s finger is moving
function touchmove(e) {
var touches = e.touches[0];

// override the touch event’s normal functionality
e.preventDefault();

// y-axis
var touchMovedY = startY - touches.pageY;
startY = touches.pageY; // reset startY for the next call
mobileScrollArea.scrollTop = mobileScrollArea.scrollTop + touchMovedY;

// x-axis
var touchMovedX = startX - touches.pageX;
startX = touches.pageX; // reset startX for the next call
mobileScrollArea.scrollLeft = mobileScrollArea.scrollLeft + touchMovedX;
}

}

代码来源: http://www.flexmls.com/developers/2011/04/13/ipad-and-single-finger-scrolling-in-flexmls/

最佳答案

将此添加到您的CSS:

-webkit-overflow-scrolling: touch;
兼容性
  • Safari : iOS 5
  • 安卓浏览器: 3.0
  • 黑莓浏览器: 6
  • 移动版 Chrome
  • 火狐手机
  • IE手机: 9
  • Opera 手机

  • example: JSfiddle

    reference: barrow.io - Overflow scrolling

    关于Javascript 平滑滚动 iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9860630/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com