Hey guys, today in this post we are going to learn about How to Create Custom Carousel Image Slider as responsive design & auto changed control by Stop/Play button uses of lightning-carousel-image in Lightning Web Component — LWC.
Here I am displaying the groups of image in the order of list in a single container in LWC component. Here in this carousel image slider displays one image at a time, and you can select particular images by clicking the round indicators at bottom of the Image.
Each slider of image displays timing for 5 seconds before the next image slide.
We can Stop/Play the auto scrolling image by control button.
Files we used in this post example
lwcCarouselSlider.html | LWc HTML File | Template HTML file used to custom lightning carousel slider with image using of lightning-carousel-image elements |
lwcCarouselSlider.js | LWC JavaScript File | There is not require JavaScript function. It is handling through lightning-carousel-image elements. |
lwcVerticalTabs.js-meta.xml | XML Meta File | It is used to where this lightning web component file you want to expose. |
lwcCarouselSliderApp | Lightning Application | It is used, call the LWC HTML file to preview on browser. |
Final Output
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
Find the below steps:-
Create Lightning Web Component HTML
Step 1:- Create Lightning Web Component HTML β‘ lwcCarouselSlider.html
SFDX:Lightning Web Component β‘ New β‘ lwcCarouselSlider.html
lwcCarouselSlider.html [Lightning Web Component HTML]
<template>
<div class="slds-p-around--medium">
<h3 class="slds-text-heading_medium"><strong style="color:#270086;">Create Custom <span style="color:#ff8000">Carousel Image Slider </span> in Lightning Web Component (LWC)</strong></h3>
<div class="slds-size_3-of-4">
<div class="slds-box slds-box_x-small slds-text-align_center slds-m-around_x-small">Basic Carousel
<lightning-carousel>
<lightning-carousel-image
src = "https://www.w3web.net/wp-content/uploads/2020/12/lwcComponentLibrary.jpg"
header = "LWC Component Library"
description = "Find the Lightning Web Component (LWC) UI Developer Guide, Component Reference and Aura Documentation Including Buttons, Icons, Input Fields ∓ Much More.."
alternative-text = "Component Library in LWC"
href = "https://www.w3web.net/find-the-lightning-web-component-library/" target="_blank">
</lightning-carousel-image>
<lightning-carousel-image
src = "https://www.w3web.net/wp-content/uploads/2020/12/componentLibraryFeature2.jpg"
header = "Developer Guide & Lightning Design System (SLDS)"
description = "A Collection of Lightning Component Library, Developer Guide and Lightning Design System (SLDS)."
alternative-text = "A Collection of Lightning Component Library."
href = "https://www.w3web.net/lightning-component-library-developer-guide/" target="_blank">
</lightning-carousel-image>
<lightning-carousel-image
src = "https://www.w3web.net/wp-content/uploads/2020/12/lwcIfElseConditionFeature.jpg"
header = "template if:true and template if:false condition in LWC"
description = "How do you use template if:true and template if:false condition to display content in lightning web component β LWC."
alternative-text = "if and else condition in lwc."
href = "https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank">
</lightning-carousel-image>
</lightning-carousel>
</div>
</div>
<br/><br/>
<!--Start RelatedTopics Section-->
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
<br/><br/>
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β</span> </strong></p>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
<li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
<li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
<li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
<li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
<li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
<li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</div>
</template>
Create Lightning Web Component Javascript
In JavaScript file there is not require JavaScript function. It is handling through lightning-carousel-image components nested in lightning-carousel library. It is a standard styling from carousel in the Lightning Design System.
Step 2:- Create Lightning Web Component Javascript β‘ lwcCarouselSlider.js
SFDX:Lightning Web Component β‘ New β‘ lwcCarouselSlider.js
lwcCarouselSlider.js [LWC JavaScript File]
import { LightningElement } from 'lwc';
export default class LwcCarouselSlider extends LightningElement {}
Create Lightning Web Component Meta XML
Step 3:- Create Lightning Web Component Meta XML β‘ lwcCarouselSlider.js-meta.xml
SFDX:Lightning Web Component β‘ New >> lwcCarouselSlider.js-meta.xml
lwcCarouselSlider.js-meta.xml [LWC Meta Data XML]
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Create Lightning Application
Step 4:- Create Lightning Application : lwcCarouselSliderApp.app
From Developer Console >> File >> New >> Lightning Application
lwcCarouselSliderApp [Component Application File]
<aura:application extends="force:slds">
<c:lwcCarouselSlider/>
</aura:application>
Further post that would you like to learn in Salesforce
What is a slider or carousel?
A slider slides the images horizontally or vertically (usually horizontally) usually with a momentum effect. A carousel rotates the images radially and in a 3D feel by using distance and depth of field. They rotate on an axis where the image is always facing you.
What is image slider?
Image sliders can be a convenient way to display multiple images, videos, or graphics on your website. The thought of big, beautiful, flashy image shows can be quite alluring. Compelling images can draw new visitors into your site, capturing their attention immediately.
How many types of sliders are there?
In generally, there are two main types: horizontal sliders and vertical sliders.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |