I am using touchSlider plugin for sliding content on mobile: https://www.mobilizetoday.com/freebies/touchslider
Below is my code that I am using to slide my content, which is 3 pictures, either by sliding with my finger, or by clicking on the big circles below my slider ( #tabs2 ). in my current code, when a #tabs2is active, .active class is added to it. That is the code for active class:
- #tabs2 a.active {
- background-color: #87c654;
- }
What I want to do is, each
#tabs2, when active, takes a certain color. Since I have 3#tabs2, I want to make 3 classes,.active1,.active2and.active3.in my javascript code, the variable
idetermines the number of#tabs2that I have. I want to add a condition that says:if(i=1){...addClass('active1')}, and same fori==2andi==3JS code:
- $(document).ready(function(){
- $('#gallery2').touchSlider({
- mode: 'index',
- center: true,
- single: true,
- onChange: function(prev, curr) {
- $('#tabs2 a.tablink').removeClass('active');
- $('#tabs2 a.tablink').filter(function(i){return i == curr}).addClass('active');
- },
- onStart: function() {
- var count = $('#gallery2').get(0).getCount();
- $('#tabs2').html('');
- for (var i = 0; i < count; i++) {
- var el = $('<a href="#" class="tablink">'+(i+1)+'</a>');
- el.attr('index', i);
- $('#tabs2').append(el);
- el.bind('click', function(){
- $('#gallery2').get(0).moveTo($(this).attr('index'));
- return false;
- });
- }
- }
- });
- });
So how is it possible to do that? what code should i add?
------EDIT-------
my html code, when loaded in the browser:
- <div id="tabs2">
- <a href="#" class="tablink active" index="0">1</a>
- <a href="#" class="tablink" index="1">2</a>
- <a href="#" class="tablink" index="2">3</a>
- </div>
All i have in my code is:
<div id="tabs2"></div>Javascript is adding the rest one my page is loaded.