jQuery Timeline.js Demo Page

这是一个使用jQuery和Timeline.js库创建的时间线布局示例。页面加载完成后,通过jQuery的$(document).ready()函数初始化时间线。时间线包含三个区块,每个区块都有一个标题,如'Block 1'、'Block 2'和'Block 3',并以左右交替的方式展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script>

/*

    Timeline - Responsive, jQuery-based timeline
    Version 1.0.0
    Ryan Fitzgerald
    http://RyanFitzgerald.ca/
    ---
    Repo: http://github.com/ryanfitzgerald/timeline
    Issues: http://github.com/ryanfitzgerald/timeline/issues
    Licensed under MIT Open Source

 */

 (function ( $ ) {

    $.fn.timeline = function(options) {

        // Overide defaults, if any
        var settings = $.extend({
            startSide: 'left',
            alternate: true,
        }, options);

        // Allow chaining and process each DOM node
        return this.each(function() {

            // Define variables
            $wrapper = $(this); // Main wrapping classes
            $userContent = $(this).children('div'); // user created divs

            // Add wrapper class
            $wrapper.addClass('timeline-wrap');

            // Create timeline divs
            $userContent.each(function() {
                // Add wrapping divs to each user div
                $(this).addClass('timeline-user')
                        .wrap('<div class="timeline-point"><div class="timeline-content"></div></div>');
            });

            // Add timeline icon
            $('.timeline-point').each(function() {
                $(this).prepend('<div class="timeline-icon"></div>');
            });

            // --- Orientation Setup ---
            // Add appropriate classes for non-alternating
            if (!settings.alternate) {
                var side = settings.startSide;
                $wrapper.addClass('timeline-wrap-'+side);
                $('.timeline-point').each(function() {
                    $(this).addClass('timeline-'+side);
                    $(this).children('.timeline-icon').addClass('timeline-icon-'+side);
                    $(this).children('.timeline-content').addClass('timeline-content-'+side);
                });
            }

            // --- Alternating Setup ---
            // Add alternating class if set to true
            if (settings.alternate && settings.startSide == 'left') {
                $('.timeline-point:odd').each(function() {
                    $(this).addClass('timeline-right');
                });
            } else if (settings.alternate && settings.startSide == 'right') {
                $('.timeline-point:even').each(function() {
                    $(this).addClass('timeline-right');
                });
            }

        });

    };

}( jQuery ));

</script>

<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">

<script>
$(document).ready( function() {
    $('#test-class').timeline();
});
</script>


<div id="test-class" class="timeline-wrap">
    <div class="timeline-point"><div class="timeline-icon"></div><div class="timeline-content"><div class="timeline-user">
        <h2>Block 1</h2>
    </div></div></div>
    <div class="timeline-point timeline-right"><div class="timeline-icon"></div><div class="timeline-content"><div class="timeline-user">
        <h2>Block 2</h2>
    </div></div></div>
    <div class="timeline-point"><div class="timeline-icon"></div><div class="timeline-content"><div class="timeline-user">
        <h2>Block 3</h2>
    </div></div></div>
</div>


CSS:

<style>

/*

    Timeline - Responsive, jQuery-based timeline
    Version 1.0.0
    Ryan Fitzgerald
    http://RyanFitzgerald.ca/
    ---
    Repo: http://github.com/ryanfitzgerald/timeline
    Issues: http://github.com/ryanfitzgerald/timeline/issues
    Licensed under MIT Open Source

 */
.timeline-wrap {
  position: relative;
  padding: 30px 0;
  margin: 0 30px; }
  .timeline-wrap:before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    height: 100%;
    width: 4px;
    background: #b1c3cf; }

.timeline-point {
  position: relative;
  clear: both;
  content: "";
  display: table;
  width: 100%; }

.timeline-content {
  margin-bottom: 30px;
  width: 45%;
  min-height: 60px;
  color: #fff;
  background-color: #E86361; }
  .timeline-content:after {
    content: ' ';
    left: 45%;
    top: 20px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 10px solid #E86361;
    position: absolute; }

.timeline-right .timeline-content {
  float: right; }
  .timeline-right .timeline-content:after {
    left: auto;
    right: 45%;
    top: 20px;
    border-left: none;
    border-right: 10px solid #E86361;
    position: absolute; }

.timeline-user {
  padding: 15px; }

.timeline-icon {
  position: absolute;
  margin-left: -13px;
  top: 15px;
  left: 50%;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #e73c3c; }

.timeline-wrap-right:before {
  left: 0; }
.timeline-wrap-right .timeline-content-right {
  margin-left: 10%;
  width: 90%; }
  .timeline-wrap-right .timeline-content-right:after {
    left: auto;
    right: 90%;
    border-left: none;
    border-right: 10px solid #eee; }
.timeline-wrap-right .timeline-icon-right {
  left: 0; }

.timeline-wrap-left:before {
  left: auto;
  right: 0; }
.timeline-wrap-left .timeline-content-left {
  margin-left: 0;
  margin-right: 10%;
  width: 90%; }
  .timeline-wrap-left .timeline-content-left:after {
    right: auto;
    left: 90%;
    border-right: none;
    border-left: 10px solid #eee; }
.timeline-wrap-left .timeline-icon-left {
  left: auto;
  right: 0;
  margin-right: -13px; }

@media only screen and (max-width: 768px) {
  .timeline-wrap:not(.timeline-wrap-left) {
    margin: 0 15px; }
    .timeline-wrap:not(.timeline-wrap-left):before {
      left: 0; }

  .timeline-content {
    margin-left: 10%;
    width: 90%; }
    .timeline-content:after {
      left: auto;
      right: 90%;
      border-left: none;
      border-right: 10px solid #eee; }

  .timeline-icon {
    left: 0;
    width: 25px;
    height: 25px;
    top: 17px;
    margin-left: -11px; }

  .timeline-right .timeline-content {
    float: none; }
    .timeline-right .timeline-content:after {
      left: auto;
      right: 90%; } }

/*# sourceMappingURL=timeline.css.map */

</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值