You need to sign in to do that
Don't have an account?
Implementing Image slider in VisualForce
I am tryng to implement Image Slider in visualforce. This is my code so far can anyone please help me with this. In this code i have added 3 images but Its only showing the first image and slider is also not working.
<apex:page showHeader="false" sidebar="false" standardStylesheets="false">
<html lang="en">
<head>
<!-- Bootstrap core CSS -->
<apex:stylesheet value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/css/bootstrap.min.css')}"/>
<title>Image Slider Using Bootstrap</title>
<!-- <apex:image alt="Challenge Image1" title="Challenge1" url="{!URLFOR($Resource.Challenge1, 'Challenge1.jpg')}"/> -->
<!-- <apex:image url="{!$Resource.Challenge1}"/> -->
</head>
<body>
<div class="container text-center">
<!-- Inside body ----------------------------------------------------------------------------------------------------------------------------------- -->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge1}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge2}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge3}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
</div><!-- Wrapper for slides End -->
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div> <!-- Carousel -->
<!--Inside Body end -------------------------------------------------------------------------------------------------------------------------------- -->
</div>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
<apex:includescript value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/js/bootstrap.min.js)"/>
<apex:includeScript value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/js/bootstrap.js)"/>
</body>
</html>
</apex:page>
<apex:page showHeader="false" sidebar="false" standardStylesheets="false">
<html lang="en">
<head>
<!-- Bootstrap core CSS -->
<apex:stylesheet value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/css/bootstrap.min.css')}"/>
<title>Image Slider Using Bootstrap</title>
<!-- <apex:image alt="Challenge Image1" title="Challenge1" url="{!URLFOR($Resource.Challenge1, 'Challenge1.jpg')}"/> -->
<!-- <apex:image url="{!$Resource.Challenge1}"/> -->
</head>
<body>
<div class="container text-center">
<!-- Inside body ----------------------------------------------------------------------------------------------------------------------------------- -->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge1}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge2}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<!-- <img src="http://placehold.it/1200x315" alt="..." /> -->
<apex:image url="{!$Resource.Challenge3}"/>
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
</div><!-- Wrapper for slides End -->
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div> <!-- Carousel -->
<!--Inside Body end -------------------------------------------------------------------------------------------------------------------------------- -->
</div>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
<apex:includescript value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/js/bootstrap.min.js)"/>
<apex:includeScript value="{!URLFOR($Resource.bootstrap, 'bootstrap-3.3.6-dist/js/bootstrap.js)"/>
</body>
</html>
</apex:page>
Mark it as answer.
Cheers
Hi Manish,
I tried your code but its working same as my code. The main thing is image are not changing automatically.
Your code was missing some quotes because of which slider was not working when I tried, also these quotes error are hard to identify, if one has not written the code.
for changing the image automatically you have to just change line no 15 to :-
if you want the image to change automatically in 3 seconds.
Hope this may help you.
Thanks for your help, My image slider is working now by adding these lines.
<script>
$('.carousel').carousel({
interval: 3000
})
</script>
Thank you very much for your time and help.
I have a question related to this slider
I tried your code to implement slider..it works when i clik preview, but i can't add it as a VF page in layout ..I don't even find it. What's wrong ?