【问题标题】:How to disable WebView scrolling in Windows 8.1如何在 Windows 8.1 中禁用 WebView 滚动
【发布时间】:2016-03-22 20:09:17
【问题描述】:

我正在为 Windows 8.1 开发应用程序。我试过下面的代码它不起作用。

<WebView Source="http://wikipedia.org" 
    ScrollViewer.VerticalScrollBarVisibility="Disabled" 
    ScrollViewer.VerticalScrollMode="Disabled"/>

是否有任何 JavaScript 解决方案来禁用触摸、鼠标和键盘滚动?

【问题讨论】:

  • 我很确定卷轴是 JS。页面是如何加载的,你在加载什么?您可以使视图足够大,然后使用缩放变换来适应它。这是我看到其他开发人员所做的,但可能还有其他方法。我在用手机,但稍后当我有我的电脑时,我会整理一个演示。希望这会有所帮助:) webview 在很多方面都很烦人......
  • WebView 的滚动条由 Web 浏览器实例显示,因此您无法通过 XAML 控制它们。

标签: windows-runtime windows-store-apps winrt-xaml windows-8.1


【解决方案1】:

我使用下面给出的 JS 来满足我的要求。虽然我在等待更好的 (XAML) 解决方案。

function RemoveScrolling() 
{
    var styleElement = document.createElement('style');
    var styleText = 'body, html { overflow: hidden; }'
    var headElements = document.getElementsByTagName('head');
    styleElement.type = 'text/css'; 
    if (headElements.length == 1) 
    { 
       headElements[0].appendChild(styleElement); 
    } 
    else if (document.head) 
    { 
        document.head.appendChild(styleElement); 
    } 
    if (styleElement.styleSheet) 
    { 
        styleElement.styleSheet.cssText = styleText; 
    } 
}

【讨论】:

  • 啊,用 JavaScript 做吧。
  • 由于浏览器实际上只是 Internet Explorer 的一个实例(已包装),因此禁用它的最佳方法是使用 CSS,就像您所做的那样。
  • 我做了一个 window.addEventListener('load',RemoveScrolling);它没有工作:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
相关资源
最近更新 更多