ios - ios 中的 WKWebView。如何使用属性禁用页面子元素的滚动反弹 - 溢出:(自动||滚动)
问题描述
我发现了很多类似的问题。
解决方案是这样的:
wkWebView.scrollView.bounces = NO;
wkWebView.scrollView.alwaysBounceHorizontal = NO;
wkWebView.scrollView.alwaysBounceVertical = NO;
它有效,但仅适用于页面的顶级元素(html、body)。
我正在寻找以下施工的解决方案:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Scroll bounce behavior</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
body, html{width: 100%; height: 100%; background: white;}
.scroll-area{
width: 200px;
height: 400px;
overflow: auto;
margin: 10px 0;
background: yellow;
}
.scroll-content{
width: 1000px;
height: 1000px;
background: repeating-radial-gradient(black, transparent 100px);
}
</style>
</head>
<body>
<div class="wrapper">
<div class="scroll-area">
<div class="scroll-content"></div>
</div>
<div class="scroll-area">
<div class="scroll-content"></div>
</div>
</div>
</body>
</html>
对于身体滚动wkWebView.scrollView.bounces = NO;
正在工作,但对于.scroll-area
不是。
我尝试了一些js解决方案,有点:
document.querySelector('.scroll-area').addEventListener('scroll', function(){
if( this.scrollTop <= 0 ){
console.warn('this.scrollTop: ' + this.scrollTop);
this.scrollTop = 0;
/*
this.style['overflow-y'] = 'hidden';
setTimeout(function(){
this.style['overflow-y'] = 'auto';
}.bind(this), 0);
*/
}
if( this.scrollLeft <= 0 ){
console.warn('this.scrollLeft : ' + this.scrollLeft );
this.scrollLeft = 0;
/*
this.style['overflow-x'] = 'hidden';
setTimeout(function(){
this.style['overflow-x'] = 'auto';
}.bind(this), 0);
*/
}
}, true);
但是当滚动到滚动区域的边界时,这种方法会导致故障。
关于的建议:
...addEventListener('touchstart, touchmove' ...
if( ...condition... )
event.preventDefault();
...
也不是很好的决定。当滚动同时具有 x 和 y 方向时会出现问题。并且在通过快速滑动调用滚动时无济于事。
对我来说最好的解决方案是永久禁用 html 页面所有元素的滚动反弹行为,WKWebView
而不使用 js、css。
有可能的?
提前致谢。
解决方案
推荐阅读
- docker - 使用 docker-compose up 命令时如何打印日志
- html - Css链接焦点在移动设备中不起作用
- mongodb - 为什么按子文档字段排序的mongodb速度这么慢?
- pandas - pandas 中不推荐使用 .item() 以及重写它的替代方法
- ant - 未解决的依赖项 IVY APACHE POI 3.13
- python - os.listdir 不工作:脚本只抓取文件名而不是数据
- charts - 这个特定的图表是如何在 Power BI 中创建的?
- clojure - delay 和 defonce 都给出了相似的结果
- linq - IGrouping 不包含 Sum 的定义
- c# - 如何在数据表中按列名添加新行