2012-11-29 55 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屬性。