简体   繁体   English

Android浏览器bug? div溢出滚动

[英]Android browser bug? div overflow scrolling

Can you make the overflow content of a div scrollable in the Android browser? 你可以在Android浏览器中使div的溢出内容可滚动吗?

It is scrollable in all other modern browsers. 它可以在所有其他现代浏览器中滚动。

In iOS it is scrollable - however it does not show scrollbars - but it is scrollable via dragging. 在iOS中它是可滚动的 - 但它不显示滚动条 - 但它可以通过拖动滚动。

A simple example: http://jsfiddle.net/KPuW5/1/embedded/result/ 一个简单的例子: http//jsfiddle.net/KPuW5/1/embedded/result/

Will this be fixed soon? 这会很快修好吗?

Android 3.0 and higher have support for overflow:scroll , on < 3.0 it's another story. Android 3.0及更高版本支持overflow:scroll ,在<3.0这是另一个故事。 You might have some success with polyfills like iScroll, however that does come at a cost. 你可能在像iScroll这样的polyfill上取得了一些成功,但这确实需要付出代价。 It's difficult to implement on sites with complex layouts, and you need to a call a method everytime the content on your site changes. 在具有复杂布局的网站上实施很困难,并且每当网站上的内容发生变化时,您都需要调用方法。 Memory use is also an issue: on already underpowered devices performance may lag because of these kinds of polyfills. 内存使用也是一个问题:在已经动力不足的设备上,由于这些类型的polyfill,性能可能会滞后。

I would recommend a different approach: use Modernizr to detect support for overflow scrolling , add a class to your html tag and use that to rewrite your CSS so that pages scroll 'normally' instead of in a box. 我建议采用不同的方法:使用Modernizr检测对溢出滚动的支持,在html标记中添加一个类,并使用它来重写CSS,使页面“正常”滚动而不是在框中滚动。

/* For browsers that support overflow scrolling */
#div {
    height: 400px;
    overflow: auto;
}

/* And for browsers that don't */
html.no-overflowscrolling #div {
    height: auto;
}

overflow: scroll; is supported as of Android 3 (API 11). 从Android 3(API 11)开始支持。

For a cross-platform (namely iOS <=4.3.2) Cubiq iScroll is an easy-to-implement fix. 对于跨平台(即iOS <= 4.3.2), Cubiq iScroll是一个易于实现的修复程序。

您可以尝试touchscoll.js用于可滚动的div元素

Just for completeness: 只是为了完整性:

The scrollbars are actually there in Android 2.3, but they are very buggy and by default they are styled to have 0 width, so they are invisible. 滚动条实际上​​存在于Android 2.3中,但它们非常多,并且默认情况下它们的样式为0宽度,因此它们是不可见的。

You can make them visible by adding styling like: 你可以通过添加样式来使它们可见:

::-webkit-scrollbar {
    width: 30px;
}
::-webkit-scrollbar-track {
    background-color: $lightestgrey;
}
::-webkit-scrollbar-thumb {
    background-color: $lightgrey;
}

However, the thumb element is not draggable, you can only move it by tapping the track underneath or above it. 但是,拇指元素不可拖动,您只能通过点击其下方或上方的轨道来移动它。

Also, these styles will change the look of your scrollbars in all webkit browsers, so best you should add a class that only applies to Android 2.3. 此外,这些样式将改变所有webkit浏览器中滚动条的外观,因此最好添加一个仅适用于Android 2.3的类。

You can make a DIV scrollable in Android by defining the styles of the scrollbar in your CSS. 您可以通过在CSS中定义滚动条的样式,在Android中滚动DIV。 This article show you how to do it: http://css-tricks.com/custom-scrollbars-in-webkit/ 本文将向您展示如何执行此操作: http//css-tricks.com/custom-scrollbars-in-webkit/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM