How we can create a product’s image slider using JS or any JS library? Solution: See this Fancybox Product Slider With Autoplay and Lightbox, Landscape-Vertical Both.
Previously I have shared many sliders, but this slider is for present eCommerce products. Basically, a product slider is a little different from basic image sliders it has small thumbnails of all images to see other images and click to choose. There also navigation buttons like next and previous for change images by sliding and the click to jump feature both.
Today you will learn to create a Product Slider with multiple features. Basically, there are two types of slider one is with landscape position and one is verticle slider. Also, the slider contains many features like the next/previous button, thumbnail image with click to jump, image lightbox, and autoplay slides. And the coolest feature is you can see all the images of 2 sliders with a lightbox view and a small thumbnail of the images in the right side.
So, Today I am sharing Fancybox Product Slider With Autoplay and Lightbox. There I have used jQuery and 2 other libraries for creating the program. The first library is lightslider.js and the second library is fancybox.js because these two libraries handling the main features. Because of using the library there are fewer CSS and JS codes. You can use this program on your website for presenting any product.
If you are thinking now how this product slider and lightbox actually is, then see the preview given below.
Preview Of Landscape/Vertical Ecommerce Slider
See this video preview to getting an idea of how this slider and the whole program look like.
Now you can see this visually, also you 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:
Fancybox Product Slider With Autoplay and Lightbox Source Code
Before sharing source code, get the source code of its. First I have created a main div and put two lists inside it to create two types of sliders. The first list is for landscape type slider and the second one is for the vertical slider. Inside each list item, I have put one image 3 times because of lightbox, thumbnail and slide image. Also in the HTML file, I have linked other files like CSS, JS, lightslider.js, and fancybox.js.
Now using CSS I have done little things like image size in slider and basic margin padding. There I have used JS libraries and JQuery plugin, that’s why there is very less line of CSS codes. In the JavaScript file, I have declared the slider’s values loop, items count, etc. We just have to put values because there are pre-built functions to call.
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. First file for HTML, the second one for CSS, and the third file for JavaScript. Follow these 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 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 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com ) --> <html lang="en" > <head> <meta charset="UTF-8"> <title>Product Slider | Webdevtrick.com</title> <link rel='stylesheet' href='https://sachinchoolur.github.io/lightslider/dist/css/lightslider.css'> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css'><link rel="stylesheet" href="./style.css"> </head> <body> <div class="main-wrapper"> <div class="demo"> <h2 style="text-align: center;">Product Slider</h2> <ul id="lightSlider"> <li data-thumb="https://webdevtrick.com/wp-content/uploads/programming.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/programming.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/programming.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/hardware.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/hardware.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/hardware.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/gadget.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/gadget.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/gadget.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/design.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/design.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/design.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/cons.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/cons.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/cons.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/auto.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/auto.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/auto.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/black-background.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/black-background.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/black-background.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/coding.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/coding.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/coding.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/1st.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/1st.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/1st.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg" /> </a> </li> </ul> <h2 style="text-align: center; margin-top: 60px;">Product Slider Verticle</h2> <ul id="lightSliderVertical"> <li data-thumb="https://webdevtrick.com/wp-content/uploads/programming.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/programming.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/programming.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/hardware.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/hardware.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/hardware.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/gadget.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/gadget.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/gadget.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/design.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/design.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/design.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/cons.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/cons.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/cons.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/auto.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/auto.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/auto.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/black-background.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/black-background.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/black-background.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/coding.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/coding.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/coding.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/1st.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/1st.jpg" data-fancybox="gallery"> <img src="https://webdevtrick.com/wp-content/uploads/1st.jpg" /> </a> </li> <li data-thumb="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg"> <a href="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg" data-fancybox="gallery" data-image="Image #10"> <img src="https://webdevtrick.com/wp-content/uploads/sunset-background.jpg" /> </a> </li> </ul> </div> </div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lightslider/1.1.6/js/lightslider.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.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 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ body{ font-family: sans-serif; } .demo { width:780px; margin: 20px auto; } #lightSlider { list-style: none outside none; padding-left: 0; margin-bottom:0; } li { display: block; float: left; cursor:pointer; } img { display: block; height: auto; width: 780px; height: 520px; } .lSSlideOuter .lSPager.lSGallery li { opacity: 0.5; } .lSSlideOuter .lSPager.lSGallery li.active { opacity: 1; } lSSlideOuter .lSPager.lSGallery li.active, .lSSlideOuter .lSPager.lSGallery li{ border-radius: 0; } lSSlideOuter .lSPager.lSGallery li.active:hover, .lSSlideOuter .lSPager.lSGallery li:hover { border-radius: 0; } .lSSlideOuter .lSPager.lSGallery img { display: block; height: 64px; max-width: 100%; } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the files.
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 |
//Code By Webdevtrick ( https://webdevtrick.com ) $ = jQuery; $( document ).ready(function() { $h_slider_options = { gallery: true, item: 1, loop:true, slideMargin: 0, thumbItem: 6, galleryMargin: 10, thumbMargin: 10, }; $v_slider_options = { gallery: true, item: 1, loop:true, slideMargin: 0, thumbItem: 6, galleryMargin: 10, thumbMargin: 10, vertical: true }; h_slider = $('#lightSlider').lightSlider($h_slider_options); v_slider = $('#lightSliderVertical').lightSlider($v_slider_options); $selector = '#lightSlider li:not(".clone") a'; $selector += ',#lightSliderVertical li:not(".clone") a'; $().fancybox({ selector : $selector, backFocus : false, buttons : [ 'slideShow', 'share', 'zoom', 'fullScreen', 'thumbs', 'download', 'close' ] }); }); $( window ).resize(function() { slider.destroy(); h_slider = $('#ocassions-slider').lightSlider(h_slider_options); }); |
That’s It. Now you have successfully created Fancybox Product Slider With Autoplay and Lightbox, Landscape-Vertical type of slider. If you have any doubt or questions comment down below.
Thanks For Visiting, Keep Visiting.
Hi!
Nice example – it’s very important to me!
But one quiestion – about last two rows in function.js
When I run this and see in browser console – I see two errors indicate about
1. slider.destroy() – not defined slider
2. h_slider = $(‘#ocassions-slider’).lightSlider(h_slider_options) – not defined h_slider_options.
All of this – in Chrome last wersion.
Please explain me – for what this $( window ).resize(function() ….)
Thank you!
BR
Alex