How we can create a timeline slider using HTML CSS JS? Solution: See this CSS Responsive Timeline Slider With Swiper JS, HTML CSS JS Timeline.
Previously I have shared a simple Timeline Design, but this is with slider and swiper. Basically, Timeline is design pattern to show step by step methods, study and work experience, or something else like that. Normal timeline contains a straight line with some points, each point has a different time period and experience.
Today you will learn to create HTML CSS JS Timeline Design With Swiper. Basically there is a vertical timeline on the right side of the webpage, and each timeline’s item has a different image. This is a kind of Image slider or carousel with timeline concept, items slide with a button click and swipe.
So, Today I am sharing CSS Responsive Timeline Slider With Swiper JS. Here I have used a JavaScript library named Swiper for easy work, this library is specially built for this work. The item slides in the vertical direction in PC or laptop and slides horizontally on mobile and small screens. I think this program will be useful for you and also you can use this on your website.
If you are thinking now how this timeline slider actually is, then see the preview given below.
Preview Of Timeline’s Carousel
See this video preview to getting an idea of how this carousel/slider looks like.
Now you can see this visually, you also can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- Pagination with Active and Hover Effect
- JavaScript Loop Slideshow
- Google Map Marker With JS API
- Text to Grid Layout on Hover
CSS Responsive Timeline Slider With Swiper JS Source Code
Before sharing source code, let’s talk about it. First, with HTML I have created slider items, each slider contains an image, a title, some texts and years. I have used HTML Data-* element for store years which is present on carousel items. After that, I have created two arrow buttons and a div for pagination, You can also navigate by clicking on years.
Now using CSS I have placed all the elements on the right place, as you can see in the preview. I have used SVG to placing the arrow buttons, you can use any icon library for that. With CSS, I have done lots of works, like margin, padding, transform, scale, transition, etc. For creating responsive design, used CSS @media query, it will fit on every screen size.
As you know I have used the swiper library to create this design, which is a JavaScript library (get). This library has pre-built functions for creating mobile-friendly sliders. Using JS, I have done next-pre button‘s work, direct pagination function, and fetch and functioning years. Left all other things you will understand after getting the codes, I can’t explain all in writing.
For creating this program, you have to create 3 files for that. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<!DOCTYPE html> <!--Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Responsive Timeline Slider | Webdevtrick.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css'> <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,700,800'> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1 class="title">Responsive Timeline Slider</h1> <div class="timeline"> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=1);" data-year="2000"> <div class="swiper-slide-content"><span class="timeline-year">2000</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=2);" data-year="2002"> <div class="swiper-slide-content"><span class="timeline-year">2002</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=3);" data-year="2003"> <div class="swiper-slide-content"><span class="timeline-year">2003</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=4);" data-year="2005"> <div class="swiper-slide-content"><span class="timeline-year">2005</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=5);" data-year="2009"> <div class="swiper-slide-content"><span class="timeline-year">2009</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> <div class="swiper-slide" style="background-image: url(https://picsum.photos/1920/500?random=6);" data-year="2012"> <div class="swiper-slide-content"><span class="timeline-year">2012</span> <h4 class="timeline-title">Your Event Title</h4> <p class="timeline-text">Lorem ipsum dolor site amet, consectetur adipscing elit, sed do eisumod tempor incididut ut labore et dolore magna aliqua. Ut enim ad mimim venjam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> </div> </div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> <div class="swiper-pagination"></div> </div> </div> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js'></script> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ html, body, .container { height: 100%; } body { font-family: 'Open Sans', sans-serif; font-size: 14px; } .container { display: flex; justify-content: center; align-items: center; background-color: #fff; flex-direction: column; } .title { font-size: 38px; color: #616161; font-style: italic; font-weight: 800; } .timeline { width: 100%; background-color: #fff; box-shadow: 0 5px 25px 5px rgba(0, 0, 0, 0.2); } .timeline .swiper-container { height: 600px; width: 100%; position: relative; } .timeline .swiper-wrapper { transition: 2s cubic-bezier(0.68, -0.4, 0.27, 1.34) 0.2s; } .timeline .swiper-slide { position: relative; color: #fff; overflow: hidden; background-size: cover; background-repeat: no-repeat; background-position: center center; } .timeline .swiper-slide::after { content: ""; position: absolute; z-index: 1; right: -115%; bottom: -10%; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); box-shadow: -230px 0 150px 60vw rgba(0, 0, 0, 0.7); border-radius: 100%; } .timeline .swiper-slide-content { position: absolute; text-align: center; width: 80%; max-width: 310px; right: 50%; top: 13%; -webkit-transform: translate(50%, 0); transform: translate(50%, 0); font-size: 12px; z-index: 2; } .timeline .swiper-slide .timeline-year { display: block; font-style: italic; font-size: 42px; margin-bottom: 50px; -webkit-transform: translate3d(20px, 0, 0); transform: translate3d(20px, 0, 0); color: #d4a024; font-weight: 300; opacity: 0; transition: .2s ease .4s; } .timeline .swiper-slide .timeline-title { font-weight: 800; font-size: 34px; margin: 0 0 30px; opacity: 0; -webkit-transform: translate3d(20px, 0, 0); transform: translate3d(20px, 0, 0); transition: .2s ease .5s; } .timeline .swiper-slide .timeline-text { line-height: 1.5; opacity: 0; -webkit-transform: translate3d(20px, 0, 0); transform: translate3d(20px, 0, 0); transition: .2s ease .6s; } .timeline .swiper-slide-active .timeline-year { opacity: 1; -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); transition: .4s ease 1.6s; } .timeline .swiper-slide-active .timeline-title { opacity: 1; -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); transition: .4s ease 1.7s; } .timeline .swiper-slide-active .timeline-text { opacity: 1; -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); transition: .4s ease 1.8s; } .timeline .swiper-pagination { right: 15% !important; height: 100%; display: none; flex-direction: column; justify-content: center; font-style: italic; font-weight: 300; font-size: 18px; z-index: 1; } .timeline .swiper-pagination::before { content: ""; position: absolute; left: -30px; top: 0; height: 100%; width: 1px; background-color: rgba(255, 255, 255, 0.2); } .timeline .swiper-pagination-bullet { width: auto; height: auto; text-align: center; opacity: 1; background: transparent; color: #d4a024; margin: 15px 0 !important; position: relative; } .timeline .swiper-pagination-bullet::before { content: ""; position: absolute; top: 8px; left: -32.5px; width: 6px; height: 6px; border-radius: 100%; background-color: #d4a024; -webkit-transform: scale(0); transform: scale(0); transition: .2s; } .timeline .swiper-pagination-bullet-active { color: #d4a024; } .timeline .swiper-pagination-bullet-active::before { -webkit-transform: scale(1); transform: scale(1); } .timeline .swiper-button-next, .timeline .swiper-button-prev { background-size: 20px 20px; top: 15%; width: 20px; height: 20px; margin-top: 0; z-index: 2; transition: .2s; } .timeline .swiper-button-prev { left: 8%; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M0%2C22L22%2C0l2.1%2C2.1L4.2%2C22l19.9%2C19.9L22%2C44L0%2C22L0%2C22L0%2C22z'%20fill%3D'%23d4a024'%2F%3E%3C%2Fsvg%3E"); } .timeline .swiper-button-prev:hover { -webkit-transform: translateX(-3px); transform: translateX(-3px); } .timeline .swiper-button-next { right: 8%; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M27%2C22L27%2C22L5%2C44l-2.1-2.1L22.8%2C22L2.9%2C2.1L5%2C0L27%2C22L27%2C22z'%20fill%3D'%23d4a024'%2F%3E%3C%2Fsvg%3E"); } .timeline .swiper-button-next:hover { -webkit-transform: translateX(3px); transform: translateX(3px); } @media screen and (min-width: 768px) { .timeline .swiper-slide::after { right: -30%; bottom: -8%; width: 240px; height: 50%; box-shadow: -230px 0 150px 50vw rgba(0, 0, 0, 0.7); } .timeline .swiper-slide-content { right: 30%; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); width: 310px; font-size: 11px; text-align: right; } .timeline .swiper-slide .timeline-year { margin-bottom: 0; font-size: 32px; } .timeline .swiper-slide .timeline-title { font-size: 46px; margin: 0; } .timeline .swiper-pagination { display: flex; } .timeline .swiper-button-prev { top: 15%; left: auto; right: 15%; -webkit-transform: rotate(90deg) translate(0, 10px); transform: rotate(90deg) translate(0, 10px); } .timeline .swiper-button-prev:hover { -webkit-transform: rotate(90deg) translate(-3px, 10px); transform: rotate(90deg) translate(-3px, 10px); } .timeline .swiper-button-next { top: auto; bottom: 15%; right: 15%; -webkit-transform: rotate(90deg) translate(0, 10px); transform: rotate(90deg) translate(0, 10px); } .timeline .swiper-button-next:hover { -webkit-transform: rotate(90deg) translate(3px, 10px); transform: rotate(90deg) translate(3px, 10px); } } @media screen and (min-width: 1024px) { .timeline .swiper-slide::after { right: -20%; bottom: -12%; width: 240px; height: 50%; box-shadow: -230px 0 150px 39vw rgba(0, 0, 0, 0.7); } .timeline .swiper-slide-content { right: 25%; } } |
function.js
The final step, Create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// Code By Webdevtrick ( https://webdevtrick.com ) var timelineSwiper = new Swiper ('.timeline .swiper-container', { direction: 'vertical', loop: false, speed: 1600, pagination: '.swiper-pagination', paginationBulletRender: function (swiper, index, className) { var year = document.querySelectorAll('.swiper-slide')[index].getAttribute('data-year'); return '<span class="' + className + '">' + year + '</span>'; }, paginationClickable: true, nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', breakpoints: { 768: { direction: 'horizontal', } } }); |
That’s It. Now you have successfully created a CSS Responsive Timeline Slider With Swiper JS, HTML CSS JS Timeline Design. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.
Awesome One!
Thank you.
Wow bro love these tutorial. I also try to make these. Keep it up bro
You made lecture also please give me you where I prepare for this
Hello –
Great work! Have you been able to get the breakpoint settings to update when you go from large screen to small and back to large again? I’m having some issues getting that to work. Cheers!
WOW great thanks. I need a little help. Can you please tell how can we add more swiper slides in it?
Boosting this question. Same issue here. I need to be able to add more dates to the slider. When I do, the numbers disappear off the div, and cover up the arrows. Not sure how to fix that. I suspect it’s not just a CSS issue, but also a js one.
I love this so much! But I’m having trouble getting it to work on a bootstrap website. It doesn’t seem to be able to read the .js file. I’ve tried putting it in the header, just above /body, I’ve tried putting the code between tags above /body. But it’s just not working. It works fine in Codepen. Not sure what’s going on. Any ideas?