function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vikash Kumar 90Vikash Kumar 90 

Carousel in Visualforce component

Hi All,

I have visualforce component implementing Carousel . Images are not sliding. Here is the component page code:

<aura:component implements="force:appHostable" >
<ltng:require styles="/resource/bootStrapCss"/>    
<ltng:require scripts="/resource/jQuery,/resource/bootStrapJS" afterScriptsLoaded="{!c.doinit}" />
    
  <div class="container">
  <h2>Activate Carousel with JavaScript</h2>
  <div id="myCarousel" class="carousel slide">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="item1 active"></li>
      <li data-target="#myCarousel" data-slide-to="1" class="item2"></li>
      <li data-target="#myCarousel" data-slide-to="2" class="item3"></li>
      <li data-target="#myCarousel" data-slide-to="3" class="item4"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">

      <div class="item active">
          <img src="http://mu.ac.in/portal/wp-content/uploads/2012/01/univeristy-of-mumbai.jpg" alt="Chania"  height="345"></img>
        <div class="carousel-caption">
          <h3>Chania</h3>
          <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
        </div>
      </div>
    <div class="item">
        <img src="http://studentcompetitions-general.s3.amazonaws.com/cyp-2014/img/lundsuniversitet_-_b.jpg" alt="Chania"  height="345"></img>
        <div class="carousel-caption">
          <h3>Chania</h3>
          <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
        </div>
      </div>
    
      <div class="item">
        <img src="http://kinesiology.rice.edu/uploadedImages/sc_rice.jpg" alt="Flower" width="460" height="345"></img>
        <div class="carousel-caption">
          <h3>Flowers</h3>
          <p>Beatiful flowers in Kolymbari, Crete.</p>
        </div>
      </div>

      <div class="item">
        <img src="http://orientaluniversity.in/wp-content/uploads/2016/02/banner-1.jpg" alt="Flower" width="460" height="345"></img>
        <div class="carousel-caption">
          <h3>Flowers</h3>
          <p>Beatiful flowers in Kolymbari, Crete.</p>
        </div>
      </div>
  
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>
 
</aura:component>

Here is the controller code:
({
    doinit : function(component, event, helper) {
        $(document).ready(function(){
    // Activate Carousel
    $("#myCarousel").carousel();
    
    // Enable Carousel Indicators
    $(".item1").click(function(){
        $("#myCarousel").carousel(0);
    });
    $(".item2").click(function(){
        $("#myCarousel").carousel(1);
    });
    $(".item3").click(function(){
        $("#myCarousel").carousel(2);
    });
    $(".item4").click(function(){
        $("#myCarousel").carousel(3);
    });
    
    // Enable Carousel Controls
    $(".left").click(function(){
        $("#myCarousel").carousel("prev");
    });
    $(".right").click(function(){
       // alert('next start');
        $("#myCarousel").carousel("next");
        // alert('next end');
    });
});
    }
})

Please suggest any solution.
SandhyaSandhya (Salesforce Developers) 
Hi,

Not sure what is wrong in your code.But below are the links which have some sample code for the same please refer those you may get some idea.

https://developer.salesforce.com/blogs/developer-relations/2015/06/creating-carousel-lightning-component.html
 
http://ibirdstechshare.blogspot.sg/2015/09/salesforce-lightning-image-slider.html
 
Hope this helps you!

Please mark it as solved if this helps you so that it will make available for other as a proper solution.

Thanks and Regards
Sandhya
Vikash Kumar 90Vikash Kumar 90
Hi Sandhya,

I tried the second link.  I am getting the error saying " Uncaught TypeError: Cannot read property 'offsetWidth' of undefined throws at /resource/bootStrapJS:4:6975 ".
User-added image

Can you please suggest any solution.?
prithvi kumarprithvi kumar
<aura:component controller="displayImage" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <ltng:require styles="/resource/Slider/Slider/bootstrap.min.css"/>    
    <ltng:require scripts="/resource/Slider/Slider/jquery.min.js,
                           /resource/Slider/Slider/bootstrap.min.js"
   afterScriptsLoaded="{!c.myAction}"/>    
    
         <aura:handler name="init" action="{!c.myAction}" value="{!this}" />  
        <aura:attribute name="atlist" type="ImagesSlider__c"/>
        <aura:attribute name="recordId" type="Id"  />
        <aura:attribute name="recordIds" type="Id[]"  />
           <aura:attribute name="imagesUrl" type="String[]" />
        <aura:attribute name="interval" type="Integer" default="2000"/>   

    <div id="carousel-example-generic" class="carousel slide imageInterval" data-ride="carousel" >
       <aura:iteration items="{!v.atlist}" var="acc">    
        <ol class="carousel-indicators">
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">                                
                <aura:if isTrue="{!index == 0}">
                    <li data-target="#carousel-example-generic" data-slide-to="{!index}" class="active"></li>
                    <aura:set attribute="else">
                        <li data-target="#carousel-example-generic" data-slide-to="{!index}" ></li>
                    </aura:set>
                </aura:if>   
            </aura:iteration>      
        </ol>
         </aura:iteration>
        
        <div class="carousel-inner" role="listbox">  
             <aura:iteration items="{!v.atlist}" var="acc">    
            <aura:iteration items="{!acc.Imagess__r}" var="imgUrl" indexVar="index">   
                <aura:if isTrue="{!index == 0}">
                    <div class="item active" >
                        <ui:outputRichText value="{!imgUrl.UploadImage__c}" class="img-responsive"/>
                        <div class="carousel-caption"> </div>
                    </div>
                    <aura:set attribute="else" >
                        <div class="item " >
                            <ui:outputRichText value="{!imgUrl.UploadImage__c}"  class="img-responsive"/>
                            <div class="carousel-caption"> </div>
                        </div>
                    </aura:set>
                </aura:if>
                
            </aura:iteration>
                 </aura:iteration>
        </div>
    
        <a class="left carousel-control" href="" role="button" data-slide="prev" onclick="{!c.Previous}">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="" role="button" data-slide="next" onclick="{!c.Next}">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
            <span class="sr-only">Next</span>
        </a> 
    </div>
               
</aura:component>