How to make a dynamic timeline using HTML, CSS and jQuery
How to use HTML, CSS and jQuery to make a dynamic timeline, specific code examples are required
Timeline is a common way to display the time sequence and event flow method, very suitable for displaying historical events, project progress, etc. Using HTML, CSS and jQuery technology, you can easily create a dynamic timeline effect. This article will introduce how to use these techniques to achieve a simple timeline effect and provide specific code examples.
First, we need to create a basic timeline structure in HTML. The following is a code example:
<!DOCTYPE html> <html> <head> <title>动态时间轴</title> <link rel="stylesheet" type="text/css" href="styles.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="script.js"></script> </head> <body> <div class="timeline"> <div class="timeline-items"> <div class="timeline-item"> <div class="timeline-item-content"> <h2 id="事件">事件1</h2> <p>事件1的详细描述</p> </div> </div> <div class="timeline-item"> <div class="timeline-item-content"> <h2 id="事件">事件2</h2> <p>事件2的详细描述</p> </div> </div> <div class="timeline-item"> <div class="timeline-item-content"> <h2 id="事件">事件3</h2> <p>事件3的详细描述</p> </div> </div> </div> <div class="timeline-progress"></div> </div> </body> </html>
In the above HTML code, we created a .timeline
container, which contains a .timeline-items
container and a .timeline-progress
Progress bar. .timeline-items
The container is used to place events on the timeline. Each event is represented by .timeline-item
, and the details of the event are placed in .timeline-item- content
Container.
Next, we use CSS styles to beautify the appearance of the timeline. The following is a code example:
.timeline { position: relative; margin: 50px auto; width: 800px; } .timeline-items { position: relative; } .timeline-item { position: relative; margin-bottom: 50px; padding: 20px; background: #f1f1f1; } .timeline-item-content { display: inline-block; vertical-align: top; } .timeline-progress { position: absolute; width: 4px; background: #666; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); }
In the above CSS code, we set the basic style of the .timeline
container and beautify .timeline-item
and ## The appearance of #.timeline-progress.
$(document).ready(function() { var timelineItems = $(".timeline-items .timeline-item"); var progress = $(".timeline-progress"); // 设置进度条的初始位置 progress.css("height", timelineItems.length * 100); // 监听滚动事件,更新进度条位置 $(window).scroll(function() { var scrollTop = $(this).scrollTop(); var windowHeight = $(this).height(); var documentHeight = $(document).height(); var timelineOffset = $(".timeline").offset().top; var progressHeight = windowHeight * ((scrollTop - timelineOffset) / (documentHeight - windowHeight)); progress.css("top", scrollTop - timelineOffset); progress.css("height", progressHeight); }); });
The above is the detailed content of How to make a dynamic timeline using HTML, CSS and jQuery. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to achieve the playback of pictures like videos? Many times, we need to implement similar video player functions, but the playback content is a sequence of images. direct...

In React projects, we often encounter problems with the use of lifecycle functions, especially when it comes to page refresh, how to ensure that certain operations only...

Regarding the problem of inconsistent width of emsp spaces in HTML and Chinese characters in many web tutorials, it is mentioned that occupying the width of a Chinese character, but the actual situation is not...

How to achieve upward scrolling loading similar to WeChat chat records? When developing applications similar to WeChat chat records, a common question is how to...

How to realize the function of playing pictures like videos? Many times, we need to achieve similar video playback effects in the application, but the playback content is not...

Using react-transition-group in React to achieve confusion about closely following transition animations. In React projects, many developers will choose to use react-transition-group library to...

1.0.1 Preface This project (including code and comments) was recorded during my self-taught Rust. There may be inaccurate or unclear statements, please apologize. If you benefit from it, it's even better. 1.0.2 Why is RustRust reliable and efficient? Rust can replace C and C, with similar performance but higher security, and does not require frequent recompilation to check for errors like C and C. The main advantages include: memory security (preventing null pointers from dereferences, dangling pointers, and data contention). Thread-safe (make sure multi-threaded code is safe before execution). Avoid undefined behavior (e.g., array out of bounds, uninitialized variables, or access to freed memory). Rust provides modern language features such as generics

How to quickly build a front-end page in back-end development? As a backend developer with three or four years of experience, he has mastered the basic JavaScript, CSS and HTML...
