简体   繁体   English

Phonegap textarea滚动

[英]Phonegap textarea scrolling

I have a phonegap app where I have disabled the scrolling of the webview by applying document touch move and prevent.default(); 我有一个phonegap应用程序,其中通过应用文档触摸移动和prevent.default()禁用了Webview的滚动。

The problem is that I have two text areas that I would like to scroll if the text overflows. 问题是如果文本溢出,我有两个文本区域要滚动。 The prevent default interferes with this. 防止默认值会对此产生干扰。

I've tried several work arounds with mixed results and the best so far being the following function to detect the x and y of the touch move event and only applying prevent default if it falls outside of the text areas. 我已经尝试了几种解决方法,但结果却好坏参半,到目前为止,最好的方法是使用以下功能来检测触摸移动事件的x和y,并且仅在文本区域之外时才使用prevent default。

function preventBehavior(e) 
{ 
    console.log("event.targetTouches[0].pageX = " + event.targetTouches[0].pageX + " event.targetTouches[0].pageY = " + event.targetTouches[0].pageY);

    var x = event.targetTouches[0].pageX;
    var y = event.targetTouches[0].pageY;

    //fix the scroll of textareas for iOS by avoiding prevent default in them 
    if (x > 20 && x < 300 && y > 80 && y < 230){
        //touch falls within first text area
    }else if (x > 20 && x < 300 && y > 245 && y < 400){
        //touch falls within second text area
    }else{
        e.preventDefault(); 
    }
};
document.addEventListener("touchmove", preventBehavior, false);

The problem now is that if the text area does not require scrolling then it scrolls the entire web app. 现在的问题是,如果文本区域不需要滚动,则它将滚动整个Web应用程序。

Does anyone has a definitive fix for this problem? 有谁可以解决此问题?

Thanks in advance. 提前致谢。

You can use iscroll.js if u only want text field scrolling. 如果您只想滚动文本字段,则可以使用iscroll.js it also works find with desktop web browsers. 它也可以与桌面Web浏览器一起找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM