时间轴特效在网页设计中是一种常见的交互效果,它可以用来展示一系列事件或内容,按照时间顺序进行排列和展示。使用jQuery来实现时间轴特效,可以通过其强大的DOM操作和动画功能来简化开发过程。
时间轴特效通常包括以下几个元素:
以下是一个简单的线性时间轴特效的jQuery实现示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>时间轴特效</title>
<style>
.timeline {
position: relative;
max-width: 600px;
margin: 0 auto;
}
.timeline::after {
content: '';
position: absolute;
width: 6px;
background-color: #ddd;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
.timeline-item {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
.timeline-item::after {
content: '';
position: absolute;
width: 25px;
height: 25px;
right: -17px;
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;
}
</style>
</head>
<body>
<div class="timeline">
<div class="timeline-item left">
<div class="content">
<h2>2009-2011</h2>
<p>第一阶段 - 创立初期</p>
</div>
</div>
<div class="timeline-item right">
<div class="content">
<h2>2012-2014</h2>
<p>第二阶段 - 快速发展</p>
</div>
</div>
<!-- 更多时间节点 -->
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.timeline-item').click(function() {
$(this).toggleClass('active');
});
});
</script>
</body>
</html>
left
属性设置正确,避免重叠。通过上述方法,可以有效地创建和管理时间轴特效,提升用户体验。
领取专属 10元无门槛券
手把手带您无忧上云