I have a cycle 2 js code that will change the chart every 15 seconds. However, how do I include a next/previous button so that user can click to any chart they want?
HTML code
<div id="chart1">
<div id="SummaryLineChart"></div>
</div>
<div id="chart2">
<div id="DailyBarChart"></div>
</div>
<div id="chart3">
<div id="PieChart"></div>
</div>
My JS file:
jQuery(function () {
var $els = $('div[id^=chart]'),
i = 0,
len = $els.length;
$els.slice(1).hide();
setInterval(function () {
$els.eq(i).fadeOut(function () {
i = (i + 1) % len
$els.eq(i).fadeIn();
})
}, 15000)
})
first of all, we wrap your slideshow slides into a container and give every slide the same class (used as slide selector later on). then we also include a slide control div, with the previous and next elements. you can position them via css according to your needs.
my preferred infinite slideshow approach:
this creates an infinite slideshow, where the first slide is always the visible slide. this makes it a lot easier to address the current active slide...
your previous/next functions would look like that: