Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • PDF Invoice Generator
Menu

Javascript Slick Image Carousel Slider Library Animation Example Using jQuery in Website

Posted on March 27, 2023

 

Welcome folks today in this blog post we will be displaying the slick image carousel slider for multiple images using jquery and javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an index.html file and copy paste the following code

 

 

index.html

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css"
        href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" />
    <link rel="stylesheet" type="text/css"
        href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
 
</head>
<body>    
</body>
</html>

 

 

As you can see we are including the cdn of all the libraries including the jquery and the slick carousel slider library also. Now we need to define all the images that will be there inside the slider. For this we need to write custom css as well. All images will be there inside the parent class called slider and each slide will have the class slide attached to it as shown below

 

 

1
2
3
4
5
6
7
8
9
10
11
<div class="slider">
        <div class="slide">
        <img src="https://images.unsplash.com/photo-1679847727418-33ef58d86ebe?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60"/>
        </div>
        <div class="slide">
        <img src="https://images.unsplash.com/photo-1679860284313-0ddefb3f6398?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60"/>
        </div>
        <div class="slide">
        <img src="https://plus.unsplash.com/premium_photo-1666265087919-cda6817be49b?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw3fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60"/>
        </div>
      </div>

 

 

And now we need to style the above html as shown below

 

 

CSS
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
<style>
    .slider {
  width: 80%;
  margin: 0 auto;
}
 
.slick-arrow {
  display: block;
}
 
.slick-prev:before, .slick-next:before {
  color: black;
}
 
.slide {
  display: block;
  text-align: center;
}
 
.slide img {
  max-width: 100%;
  height: auto;
  display: inline-block;
  vertical-align: middle;
}
</style>

 

 

And now we need to write the javascript code for the above carousel slider of slick as shown below

 

 

JavaScript
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
$(document).ready(function(){
  $('.slider').slick({
    autoplay: true,
    autoplaySpeed: 3000,
    dots: true,
    arrows: true,
    infinite: true,
    speed: 500,
    fade: true,
    cssEase: 'linear',
    slidesToShow: 1,
    slidesToScroll: 1,
    centerMode: true,
    centerPadding: '20%',
    responsive: [
      {
        breakpoint: 768,
        settings: {
          centerPadding: '10%'
        }
      },
      {
        breakpoint: 576,
        settings: {
          centerPadding: '5%'
        }
      }
    ]
  });
});

 

 

As you can see we are using the slick() method to initialize the slider and then we are passing the series of options as shown above.

 

 

 

 

Recent Posts

  • Python 3 Flask Project to Export Multiple PDF Documents to Word Docx Files Using pdf2docx Library in Browser
  • Build a Fixed Deposit Interest Calculator Using Amount and Time in Browser Using HTML5 & Javascript
  • Python 3 Script to Convert PDF Document to Microsoft Word DOCX File Using pdf2docx Library
  • Node.js Express Project to Remove Background of Images Using Rembg & Formidable Library in Browser
  • Node.js Tutorial to Remove Background From Image Using Rembg & Sharp Library in Command Line
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme