【问题标题】:How to get the width and height of the zoomed viewport in webview?如何在 webview 中获取缩放视口的宽度和高度?
【发布时间】:2016-04-18 13:41:25
【问题描述】:

我正在使用$(window).width() and $(window).height() 来获取 webview 的宽度和高度,但这些总是返回相同的值以及整个 webview 的实际宽度和高度。

我需要的是获取用户当前只能看到的视口的宽度和高度,因此在缩放时,视口的宽度和高度应该变小。

我需要这个来将一个 div 元素放在用户只能看到的视口中。

【问题讨论】:

    标签: android jquery css webview


    【解决方案1】:

    我不太擅长 javascript,但我曾经遇到过这个问题。我记得这与目标内部宽度有关。有时您还必须考虑滚动条,具体取决于您的操作方式。

    我在这里找到了这个:Why is the window.width smaller than the viewport width set in media queries

    类似的问题。

    function viewport() {
        var e = window, a = 'inner';
        if (!('innerWidth' in window )) {
            a = 'client';
            e = document.documentElement || document.body;
        }
        return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
    }
    
    var vpWidth = viewport().width;
    

    【讨论】:

    • 它工作得很好。如果你能解释一下代码是如何工作的,那就太好了
    • 我很高兴它有效。我不知道代码是如何工作的哈哈。我只是擅长找东西。
    • 哈哈不错。现在我有另一个问题我怎样才能获得相对于浏览器的整个宽度和高度的视口 x 和 y 位置:)
    • x 和 y 位置是什么?像这样? callmenick.com/post/cross-browser-calculation-of-x-y-position
    • 我的意思是相对于整个文档的视口位置
    猜你喜欢
    • 2014-08-28
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多