&l…">
当前位置:首页 > jquery

jquery 时间线

2026-02-04 08:13:32jquery

jQuery 时间线实现方法

使用 jQuery 创建一个时间线可以通过多种方式实现,以下是一种常见的方法:

HTML 结构

<div class="timeline">
  <div class="timeline-item">
    <div class="timeline-date">2023-01-01</div>
    <div class="timeline-content">事件1描述</div>
  </div>
  <div class="timeline-item">
    <div class="timeline-date">2023-02-15</div>
    <div class="timeline-content">事件2描述</div>
  </div>
</div>

CSS 样式

.timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}
.timeline::after {
  content: '';
  position: absolute;
  width: 6px;
  background-color: #333;
  top: 0;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}
.timeline-item {
  padding: 10px 40px;
  position: relative;
  width: 50%;
  box-sizing: border-box;
}
.timeline-item::after {
  content: '';
  position: absolute;
  width: 25px;
  height: 25px;
  background-color: white;
  border: 4px solid #FF9F55;
  top: 15px;
  border-radius: 50%;
  z-index: 1;
}
.left {
  left: 0;
}
.right {
  left: 50%;
}
.left::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  right: 30px;
  border: medium solid white;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent white;
}
.right::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  left: 30px;
  border: medium solid white;
  border-width: 10px 10px 10px 0;
  border-color: transparent white transparent transparent;
}

jQuery 代码

$(document).ready(function() {
  $('.timeline-item').each(function(index) {
    if (index % 2 === 0) {
      $(this).addClass('left');
    } else {
      $(this).addClass('right');
    }
  });

  // 添加动画效果
  $('.timeline-item').hide().each(function(i) {
    $(this).delay(i * 300).fadeIn(500);
  });
});

响应式时间线实现

对于移动设备,可以调整时间线布局:

$(window).resize(function() {
  if ($(window).width() < 768) {
    $('.timeline-item').removeClass('left right').addClass('mobile');
    $('.timeline::after').css('left', '31px');
  } else {
    $('.timeline-item').removeClass('mobile');
    $('.timeline::after').css('left', '50%');
    $('.timeline-item').each(function(index) {
      if (index % 2 === 0) {
        $(this).addClass('left');
      } else {
        $(this).addClass('right');
      }
    });
  }
}).trigger('resize');

时间线插件推荐

如果需要更复杂的功能,可以考虑以下 jQuery 插件:

  • Timeliny:轻量级响应式时间线插件
  • Vertical Timelines:垂直布局时间线
  • jQuery Timeline:支持多种动画效果

这些插件通常提供更多自定义选项和交互功能,适合需要高级功能的项目。

jquery 时间线

标签: 时间jquery
分享给朋友:

相关文章

jquery文档

jquery文档

以下是关于 jQuery 文档的核心资源和使用方法整理: jQuery 官方文档 jQuery 官方文档是学习和使用 jQuery 最权威的资源,包含详细的 API 说明、示例和更新日志。…

jquery获取radio选中的值

jquery获取radio选中的值

获取radio选中的值 使用jQuery获取被选中的radio按钮的值可以通过以下几种方法实现: 方法1:使用:checked选择器 var selectedValue = $('input[…

jquery使用

jquery使用

jQuery 基础使用 jQuery 是一个快速、简洁的 JavaScript 库,简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。以下是一些常见的 jQuery 使用方法。 引入 j…

html jquery

html jquery

HTML 与 jQuery 基础 HTML 是超文本标记语言,用于构建网页的结构和内容。jQuery 是一个快速、简洁的 JavaScript 库,简化了 HTML 文档遍历、事件处理、动画和 Aja…

jquery表单

jquery表单

jQuery 表单操作 jQuery 提供了丰富的 API 用于表单操作,包括表单元素的选择、值获取与设置、事件处理等。 表单元素选择 使用 jQuery 选择器可以方便地选取表单元素: //…

jquery 隐藏

jquery 隐藏

jQuery 隐藏元素的方法 使用 jQuery 隐藏元素可以通过多种方式实现,以下是几种常见的方法: hide() 方法hide() 是最简单的隐藏元素方法,它会将元素的 display 属性设置…