Android WebView - Modal不断滚动到顶部

时间:2017-01-07 04:05:24

标签: android css webview

在这里尝试解决方案,不起作用。

Prevent BODY from scrolling when a modal is opened

模态在这里:

<style>
    /* The Modal (background) */
    .modal {
        display: none; /* Hidden by default */
        position: fixed; /* Stay in place */
        z-index: 9999; /* Sit on top */
        left: 0px;
        top: 0px;
        width: 100%; /* Full width */
        height: 100%; /* Full height */
        overflow: auto; /* Enable scroll if needed */
        background-color: rgb(0,0,0); /* Fallback color */
        background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
    }

    /* Do not remove - Prevents android from jumping to top */
    body.modal-open {
        overflow: visible;
        position: fixed;
        width: 100%;
        height:100%;
    }

    /* Modal Content/Box */
    .modal-content {
        background-color: #fefefe;
        margin: 30% auto; /* 30% from the top and centered */
        padding: 0px;
        overflow-y:auto;
        border-radius: 10px;
        border: 0px;
        max-height:70%;
        width: 80%; /* Could be more or less, depending on screen size */
    }

    /* Modal Content/Box */
    .modal-image-content {
        z-index: 99999; /* Sit on top */
        padding: 0px;
        margin: auto; /*centered */
        border: 0px;
        max-height:100%;
        max-width:100%;
    }

    /* Links inside the dropdown */
    .modal-content a {
        color: black;
        padding: 10px;
        text-decoration: none;
        display: block;
    }

    /* Links inside the dropdown */
    .modal-content a:hover{
        background-color: #dddddd;
    }

    /* The Close Button */
    .close {
        color: #aaa;
        float: right;
        font-size: 28px;
        font-weight: bold;
    }

    .close:hover,
    .close:focus {
        color: black;
        text-decoration: none;
        cursor: pointer;
    }
</style>

正如您所看到的,body.modal-open事件是从解决方案中获取的,但它不起作用。

同样,如何让模态停止使屏幕滚动到顶部?

1 个答案:

答案 0 :(得分:1)

这件事很奇怪,我的谷歌技能解决了它。

更改 ViewController

<a href="#" ...