向与 touchmove 方向相反的方向滚动
Scroll moving in the opposite direction to touchmove direction
我有一个在 NativeScript 应用程序中使用的网络视图。问题是,当滑动发生时会导致任一方向的动量滚动,如果 phone 由于资源不足而处于负载状态或者它只是在后台做某事,滚动方向将反弹到错误的方向而不是什么方向本来是刷的。代码:
<html>
<body>
<div style="height: 100000px;"> </div>
<script src="./lib/jquery-3.4.1.min.js"></script>
<script src="./my-script.js"></script>
</body>
</html>
$(document).ready(function () {
var lastY = 0; // Needed in order to determine direction of scroll.
var lastTouchDirection;
var lastScrollTop = 0;
$("div").on('touchstart', function(event) {
console.log('touchstart');
lastY = event.touches[0].clientY;
});
$('div').on('touchmove', function(event) {
console.log('touchmove');
var top = event.touches[0].clientY;
var direction = (lastY - top) < 0 ? "up" : "down";
lastTouchDirection = direction;
lastY = top;
});
$('div').on('touchend', function(event) {
console.log('touchend');
});
$(window).scroll(function(event) {
var st = $(this).scrollTop();
if (st > lastScrollTop){
console.log("downscroll")
if (lastTouchDirection == "up") {
console.log("wrong Direction")
}
} else {
console.log("upscroll")
if (lastTouchDirection == "down") {
console.log("wrong Direction")
}
}
lastScrollTop = st;
});
});
如您所见,这里没有任何独特之处,我的代码用于检查触摸事件的最后方向以及滚动当前移动的方向。我猜这与 nativescript 和我正在使用的 webview 包有关,因为我没有看到这个问题发生在 nativescript 的内置 webview 中。
我的下一步是在检测到滚动方向错误时以编程方式更正滚动方向,但我希望我能够首先纠正导致这种情况发生的任何原因。我在这里错过了什么?
NativeScript 版本:6.1.0
Web 视图包称为 nativescript-webview-interface,它用于在 nativescript 和 web 视图之间进行双向通信。
对于遇到此问题的任何人,我通过更正最终成为 nativescript 中的错误的重负载源来更正它。我不知道为什么这对 webview 有任何影响,但它就是这样。
我有一个在 NativeScript 应用程序中使用的网络视图。问题是,当滑动发生时会导致任一方向的动量滚动,如果 phone 由于资源不足而处于负载状态或者它只是在后台做某事,滚动方向将反弹到错误的方向而不是什么方向本来是刷的。代码:
<html>
<body>
<div style="height: 100000px;"> </div>
<script src="./lib/jquery-3.4.1.min.js"></script>
<script src="./my-script.js"></script>
</body>
</html>
$(document).ready(function () {
var lastY = 0; // Needed in order to determine direction of scroll.
var lastTouchDirection;
var lastScrollTop = 0;
$("div").on('touchstart', function(event) {
console.log('touchstart');
lastY = event.touches[0].clientY;
});
$('div').on('touchmove', function(event) {
console.log('touchmove');
var top = event.touches[0].clientY;
var direction = (lastY - top) < 0 ? "up" : "down";
lastTouchDirection = direction;
lastY = top;
});
$('div').on('touchend', function(event) {
console.log('touchend');
});
$(window).scroll(function(event) {
var st = $(this).scrollTop();
if (st > lastScrollTop){
console.log("downscroll")
if (lastTouchDirection == "up") {
console.log("wrong Direction")
}
} else {
console.log("upscroll")
if (lastTouchDirection == "down") {
console.log("wrong Direction")
}
}
lastScrollTop = st;
});
});
如您所见,这里没有任何独特之处,我的代码用于检查触摸事件的最后方向以及滚动当前移动的方向。我猜这与 nativescript 和我正在使用的 webview 包有关,因为我没有看到这个问题发生在 nativescript 的内置 webview 中。
我的下一步是在检测到滚动方向错误时以编程方式更正滚动方向,但我希望我能够首先纠正导致这种情况发生的任何原因。我在这里错过了什么?
NativeScript 版本:6.1.0 Web 视图包称为 nativescript-webview-interface,它用于在 nativescript 和 web 视图之间进行双向通信。
对于遇到此问题的任何人,我通过更正最终成为 nativescript 中的错误的重负载源来更正它。我不知道为什么这对 webview 有任何影响,但它就是这样。