【问题标题】:overflow-y:hidden, but still scrollable with firefox on android溢出-y:隐藏,但仍然可以在 android 上使用 firefox 滚动
【发布时间】:2015-10-31 06:01:33
【问题描述】:

我使用 jquery 在叠加​​层中打开部分视图(显示固定 div 并禁用底层网页的滚动)。这似乎适用于桌面上的 chromium 和 firefox,也适用于 chrome for android,但不适用于 firefox/android:

$('a#manage-albums').click(function(){
    $.get( this.href )
        .done(function( data ) {
            $('div#flvr-overlay-content').html(data);
            $('div#flvr-overlay-back').show();
            $('html,body').css('overflow-y','hidden');
        });
    return false;
});

覆盖出现并显示其内容,已修复,一切看起来都不错,但我仍然可以滚动底层网页..

如果这很重要,我也使用了这个元标记:

<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, user-scalable=no" />

如何在 android 上也为 firefox 禁用滚动(溢出-y)?

编辑:

看起来 Firefox 不喜欢 'overflow-y'

用这一行:

$('html,body').css('overflow','hidden');`

滚动似乎停止/减少到 Firefox 菜单栏的高度。

【问题讨论】:

  • 它是一个 HTML/PHP/JQuery 网站。我不知道 webview 是什么。
  • 我昨天解决了这个问题,最终放弃了,并从手机上删除了我的模态。但是有些人说在 body 和/或 html 中添加position: fixed 可以工作。不过,我没有测试它。
  • 我试过$('html,body').css('overflow-y','hidden').css('position','fixed');没有任何改变
  • 我不确定,但也许将 overflow: hidden !important 添加到所有带有 * 选择器的元素可以工作,然后将 overflow: auto !important 添加到您的专辑元素。不是一个很好的解决方案,但可能会奏效。
  • @haheute 你让它工作了吗?接受/赞成或两者都很好!

标签: android jquery html css scroll


【解决方案1】:

方法有很多,先试试吧

gridview.setOnTouchListener(new OnTouchListener(){

@Override
public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_MOVE){
        return true;
    }
    return false;
}

});

这就是网格视图。

Source

对于滚动视图,使用“verticalScrollDisabled = true”

或使用 (javascript)

document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });

jquery

$(document).bind('touchmove', function(e) {
    e.preventDefault();
});

未能使用 $("body").css("overflow", "hidden!important"); 并且应该可以工作

【讨论】:

  • 我试过 $('html,body').attr('style', 'overflow-y: hidden !important'); 。那没有帮助。我不明白的是,为什么chrome会这样做,而我PC上的firefox也这样做。只有 firefox/android 仍然滚动。那里一定有什么不同..
  • 还没有。我不知道在哪里和什么...并且认为它应该使用 jquery 和 css 工作。
  • 添加了一个 jquery 答案
  • 你太快了 ;) 我也想了解为什么它在 firefox/android 中不起作用
  • 你应该访问 caniuse.com 有些东西并不兼容所有的浏览器。 Firefox 存在严重问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-29
相关资源
最近更新 更多