2012-11-29 48 views
0

我的Titanium/iOS应用程序中有一个HTML选择元素的小webview。当用户进行选择时,webview会滚动。如何防止webview滚动?防止钛webview滚动?

var html = '<html>'; 
html += '<head>'; 
html += '<link rel="stylesheet" href="css/jquery.mobile-1.2.0.min.css"/>'; 
html += '<script src="lib/attributeForm.js"></script>'; 
html += '<script src="jq/jquery.min.js"></script>'; 
html += '<script src="jq/jquery.mobile-1.2.0.min.js"></script>'; 
html += '</head>'; 
html += '<body style="overflow: hidden">'; 
html += '<form style="margin:10px; min-height:500px;" id="attributeForm">'+win.attributeForm+'<br><br><br><br></form>'; 
html += '</body>'; 
html += '</html>'; 

var webview = createWebView({ 
    top: y, 
    height: 250, 
    html: html, 
    disableBounce: true, 
}); 

这里是attributeForm.js:

function getAttributes() { 
    return $('#attributeForm').serialize(); 
} 

document.body.addEventListener('touchmove', function(e) { 
    // This prevents native scrolling from happening. 
    e.preventDefault(); 
}, false); 

回答

0

的解决方案可能是在你的HTML,而不是在应用程序代码...没有看到这是很难说的任何代码,但你可以尝试在您的webview HTML的<body>上设置overflow: hidden

+0

这并没有停止滚动。我的滚动必须在由Titanium创建的界面中。 –

2

我能够通过阻止的TouchMove事件发生在Web视图实现这一目标,通过JavaScript:

document.body.addEventListener('touchmove', function(e) { 
    // This prevents native scrolling from happening. 
    e.preventDefault(); 
}, false); 

你可以看到完整的示例在这里:https://gist.github.com/819929

+0

这并没有改变我的webview中发生的滚动 - 请看这个代码添加到上面的js文件。 –

2

虽然有点晚,但应有效谁将面临同样的问题。试试.. disableBounce : true你的webview属性。