简体   繁体   English

HTML / CSS时间轴效果有些麻烦

[英]Some trouble with a HTML / CSS Timeline effect

I'm trying to a timeline effect on a project. 我正在尝试对项目产生时间轴影响。 I made some research and found this exemple 我做了一些研究,发现这个例子

And, as you can see here , it doesn't work well... Here is the part which made it : 而且,正如您在此处看到的那样,它无法正常运行...这是使它成功的部分:

section#lastPost {
  width: 960px;
  margin: 0 auto; }
section#lastPost .TLItem {
  clear: left;
  float: left; }
section#lastPost .TLItem:nth-child(2n) {
  clear: right;
  float: right; }

Well, as you can see, there is a little space problem :) 好了,正如您所看到的,有一个小空间问题:)

Any idea ? 任何想法 ?

You basically need to know the height of each block to short it out. 您基本上需要知道每个块的高度以将其缩短。 Your answer relies in this post: How do I lay out my content divs in a similar manner to Facebook Timeline? 您的答案取决于这篇文章: 如何以类似于Facebook时间轴的方式布置内容div?

And you can see the working fiddle here: http://jsfiddle.net/gK2Vn/ 您可以在这里看到有效的小提琴: http : //jsfiddle.net/gK2Vn/

In a way you need to add the following script: 在某种程度上,您需要添加以下脚本:

$(document).ready(function() {
    var left_column_height = 0;
    var right_column_height = 0;
    var items = $('section#lastPost #TL .TLItem');
    for (var i = 0; i < items.length; i++) {
        if (left_column_height > right_column_height) {
            right_column_height += items.eq(i).addClass('right').outerHeight(true);
                        } 
        else {
            left_column_height += items.eq(i).outerHeight(true);
        }
    }
});

And change your CSS to: 并将您的CSS更改为:

section#lastPost #TL .TLItem {
    clear: left;
    float: left;
}
section#lastPost #TL .TLItem.right {
    clear: right;
    float: right;
}

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

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