CSS / JavaScript中的多列垂直滚动

时间:2012-06-02 20:30:20

标签: javascript css html5 css3

目前,有没有办法用CSS在CSS或CSS中进行多列滚动?

为了描述我的意思,我已经在jsfiddle上设置了一个快速演示:

http://jsfiddle.net/S7AGp/

当div中有太多文本时,我希望能够垂直滚动,新文本从最右边的列的底部出现,而旧文本从最左边的列上方退出 - 基本上,就像文本区域,除了两列。

相反,它会产生额外的列,你必须水平滚动。

虽然我可以尝试将每行文本存储在一个数组中,然后在滚动时更改它,但我很好奇是否已经有一种方法可以在纯CSS中执行此操作,或者是否已通过JavaScript存在解决方案。谢谢!

3 个答案:

答案 0 :(得分:5)

带有垂直滚动的CSS列。

http://jsfiddle.net/MmLQL/3/

HTML

    <div runat="server" id="div_scroll">
       <div runat="server" id="div_columns">
          <p> Some text ...</p>
       </div>
    </div>

CSS

    #div_scroll {
    overflow-y: scroll;
    overflow-x: hidden;
    width: 1060px; /*modify to suit*/
    height: 340px; /*modify to suit*/
    }

    #div_columns
    {
    direction:ltr; /*column direction ltr or rtl - modify to suit*/
    columns: 3; /*number of columns - modify to suit*/
    overflow-y: hidden;
    overflow-x: hidden;
    width: 1000px; /*width of columns div has to be specified - modify to suit*/
    /* do not specify height parameter as it has to be unrestricted*/
    padding: 20px;  
    }

答案 1 :(得分:1)

我认为你在询问像css地区这样的事情:http://net.tutsplus.com/tutorials/html-css-techniques/diving-into-css-regions/

<强> HTML:

<p class="example-text">"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."</p>

<div class="regions"></div>
<div class="regions"></div> 

<强> CSS:

.example-text {
  -webkit-flow-into: example-text-flow;
  padding: 0;
  margin: 0;
}

.regions {
   -webkit-flow-from: example-text-flow;
   border: 1px solid black;
   padding: 2px;
   margin: 5px;
   width: 200px;
   height: 50px;
}

他们现在对webkit的支持有限: http://caniuse.com/css-regions

不幸的是,我不知道有任何后备或替换。

答案 2 :(得分:0)

为:
快速尝试绝对定位:http://jsfiddle.net/PhilippeVay/S7AGp/1/,想法使用bottom: 0;将文本底部定位在容器的底部。

它不起作用,因为绝对定位会从流中移除其内容,并且容器中没有任何内容(例如,您不会使用滚动条移动绝对定位的元素)。

○:
所以这是一个 solution using scrollTop()

注意:我使用了jQuery,但如果你不在项目的其他地方使用jQuery或其他框架,那么这个应该在JS中