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 | How to create custom lightning carousel with Image in lwc

6,144 views

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.

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!

 

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

lwc custom lightning carousel with image -- www.w3web.net

 

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:-

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 

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]

  1.   <template>
  2. <div class="slds-p-around--medium"> 
  3. <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>  
  4. <div class="slds-size_3-of-4">
  5.     <div class="slds-box slds-box_x-small slds-text-align_center slds-m-around_x-small">Basic Carousel
  6.         <lightning-carousel>
  7.             <lightning-carousel-image
  8.                 src = "https://www.w3web.net/wp-content/uploads/2020/12/lwcComponentLibrary.jpg"
  9.                 header = "LWC Component Library"
  10.                 description = "Find the Lightning Web Component (LWC) UI Developer Guide, Component Reference and Aura Documentation Including Buttons, Icons, Input Fields &mp; Much More.."
  11.                 alternative-text = "Component Library in LWC"
  12.                 href = "https://www.w3web.net/find-the-lightning-web-component-library/" target="_blank">
  13.             </lightning-carousel-image>
  14.             <lightning-carousel-image
  15.                 src = "https://www.w3web.net/wp-content/uploads/2020/12/componentLibraryFeature2.jpg"
  16.                 header = "Developer Guide & Lightning Design System (SLDS)"
  17.                 description = "A Collection of Lightning Component Library, Developer Guide and Lightning Design System (SLDS)."
  18.                 alternative-text = "A Collection of Lightning Component Library."
  19.                 href = "https://www.w3web.net/lightning-component-library-developer-guide/" target="_blank">
  20.             </lightning-carousel-image>
  21.             <lightning-carousel-image
  22.                 src = "https://www.w3web.net/wp-content/uploads/2020/12/lwcIfElseConditionFeature.jpg"
  23.                 header = "template if:true and template if:false condition in LWC"
  24.                 description = "How do you use template if:true and template if:false condition to display content in lightning web component – LWC."
  25.                 alternative-text = "if and else condition in lwc."
  26.                 href = "https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank">
  27.             </lightning-carousel-image>
  28.         </lightning-carousel>
  29.     </div>
  30. </div>
  31. <br/><br/>
  32.    <!--Start RelatedTopics Section-->
  33. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  34.  
  35.             <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>
  36.  
  37.             <br/><br/>
  38.             <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>
  39.             <div style="display:block; overflow:hidden;"> 
  40.                 <div style="width: 50%; float:left; display:inline-block">
  41.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  42.                         <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>
  43.                         <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>
  44.                         <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>
  45.                         <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>
  46.                         <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>
  47.                     </ul>
  48.             </div>
  49.  
  50.             <div style="width: 50%; float:left; display:inline-block">
  51.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  52.                         <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>
  53.                         <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>
  54.                         <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>
  55.                         <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>
  56.                         <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>
  57.                     </ul>
  58.                 </div>
  59.                <div style="clear:both;"></div> 
  60.                <br/>
  61.                 <div class="youtubeIcon">
  62.                     <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>
  63.                 </div>
  64.     </div>
  65.  
  66. </div>
  67.  
  68.   <!--End RelatedTopics Section-->
  69. </div> 
  70. </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]

  1.   import { LightningElement } from 'lwc';
  2.  
  3. 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]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets>
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.       </targets>
  10. </LightningComponentBundle>

Create Lightning Application

Step 4:- Create Lightning Application : lwcCarouselSliderApp.app

From Developer Console >> File >> New >> Lightning Application

lwcCarouselSliderApp [Component Application File]

  1.    <aura:application extends="force:slds">
  2.     <c:lwcCarouselSlider/>
  3. </aura:application>

lwc custom lightning carousel with image -- www.w3web.net

Further post that would you like to learn in Salesforce

 


 

FAQ (Frequently Asked Questions)

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

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

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



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment