BXslider active class on center div with 5 slides
NickName:Jeremy Love Ask DateTime:2015-06-11T08:24:25

BXslider active class on center div with 5 slides

I am literally pulling my hair out on this problem. I have 5 slides in the bxslider and I am trying to have a active class on the 3rd slide out of the 5 slides on the page, which it does when the slide 1st loads... Now when I click the next button the 1st time the active class does not go to the next element. It stays on the current slide and then moves to the next slide the 2nd time I click the next button. So im thinking the next() function isnt working. Or is it something im doing wrong?

jQuery(function($){
	
var slider = $('.bxslider').bxSlider({
 minSlides: 1,
  moveSlides:1,
  maxSlides: 5,
   pager:false,
  controls:false,
  slideWidth: 360,
  slideMargin: 0,
    onSlideBefore : function($slideElement, oldIndex, newIndex){ // your code here 

$(".bxslider li").removeClass("active-slide");
        $slideElement.next().addClass("active-slide");
},
    onSliderLoad:function(index){
       
$(".bxslider li").eq(1+$(".bxslider .bx-clone").length/3).addClass("active-slide");
    }
});
   
    
$('#slider-next').click(function(){
  slider.goToNextSlide();
    
  return false;
});
$('#slider-prev').click(function(){
  slider.goToPrevSlide();
  
  return false;
});

});
.active-slide{
background:#f00 !important;
}

.scorboard {
	float: left;
	width: 100%;
	height: 168px;
	background-image: url(images/scor-bg.png);
	background-repeat: no-repeat;
	background-position: center top;
	color: #000;
	padding-top: 22px;
}
.scorboard li {
	background-color:#ccc;
    margin:0 5px;
}
.scorboard .opponent {
	float: left;
	font-size: 18px;
	width: 42%;
	text-align: center;
}
.scorboard .lss {
	float: left;
	font-size: 18px;
	width: 42%;
	text-align: center;
}
.scorboard .lss h4 {
	text-align:left;
}
.scorboard .opponent h4 {
	text-align:right;
}
.vs {
	  float: left;
  margin: 26px 10px 0px 10px;
  width: 10%;
  text-align: center;
}
.scorboard h2 {
	font-size: 14px;
	font-family: 'octin_sportsregular';
	margin-top: 26px;
	margin-bottom: 2px;
	text-align: center;
	float: left;
	width: 100%;
}
.scorboard h3 {
	font-size: 18px;
	font-weight: bold;
	color: #b90000;
	margin-top: 3px;
	text-align: center;
	float: left;
	width: 100%;
	font-family: 'octin_sportsregular';
}
.scorboard h4 {
	float: left;
	width: 100%;
}
li.active {
  transform: scale(1.2);
  top: -9px;
    background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="http://bxslider.com/lib/jquery.bxslider.css" rel="stylesheet"/>
<script src="http://bxslider.com/lib/jquery.bxslider.js"></script>
<div class="scorboard">
  <ul  class="bxslider">
    <li>
      <h2>4/30/15 6:00 pm</h2>
      <div class="opponent">
        <h4>Pistons85</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          105</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/13/15 12:00 am</h2>
      <div class="opponent">
        <h4>Nuggets101</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          98</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/12/15 12:00 am</h2>
      <div class="opponent">
        <h4>Hawks105</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          102</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>4/24/15 6:00 pm</h2>
      <div class="opponent">
        <h4>Trail Blazers97</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          101</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/2/15 12:00 am</h2>
      <div class="opponent">
        <h4>Jazz101</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          98</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>4/30/15 6:00 pm</h2>
      <div class="opponent">
        <h4>Pistons85</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          105</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/13/15 12:00 am</h2>
      <div class="opponent">
        <h4>Nuggets101</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          98</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/12/15 12:00 am</h2>
      <div class="opponent">
        <h4>Hawks105</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          102</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>4/24/15 6:00 pm</h2>
      <div class="opponent">
        <h4>Trail Blazers97</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          101</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>5/2/15 12:00 am</h2>
      <div class="opponent">
        <h4>Jazz101</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          98</h4>
      </div>
      <h3>Final</h3>
    </li>
    <li>
      <h2>4/30/15 6:00 pm</h2>
      <div class="opponent">
        <h4>Pistons85</h4>
      </div>
      <div class="vs">vs</div>
      <div class="lss">
        <h4> LSS
          105</h4>
      </div>
      <h3>Final</h3>
    </li>
  </ul>
</div>
<div class="outside">
  <span id="slider-prev">pre</span> | <span id="slider-next">next</span>
</div>

Copyright Notice:Content Author:「Jeremy Love」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30769578/bxslider-active-class-on-center-div-with-5-slides

More about “BXslider active class on center div with 5 slides” related questions

BXslider active class on center div with 5 slides

I am literally pulling my hair out on this problem. I have 5 slides in the bxslider and I am trying to have a active class on the 3rd slide out of the 5 slides on the page, which it does when the s...

Show Detail

Center aligning dynamic slides within carousel (BXSlider)

I am struggling to get the slides to center align within the wrapper. My carousel can have a dynamic number of slides and therefore may not fill the width of the wrapper. They are aligned left by d...

Show Detail

Center slides in bxslider

I have a bxslider which is full width of the page when theyre is not enough slides to make it slide i want the slides to center inside the wrapper, i have tried using text-align center and margins ...

Show Detail

how to center slides in bxslider, so no slides are cropped

Please take a look at the current site I'm developing: http://debourg-dev.ch/eliterent/ For the bottom brand logo slider, I am using bxslider. I'm wondering if there is a way to center the slides (...

Show Detail

Vertically center-align div in BxSlider Carousel

I'm using bxslider script to build a carousel. I can do everything fine, I'm just having a problem trying to align to center the slides vertically, as they don't have the same height. I've tried nu...

Show Detail

bxSlider jquery showing random slides?

Hi guys I am using the jquery bxslider plugin, and for some reason it shows random slides, it doesn't start at one, and sometimes it will show the first slide multiple times, and some slides never?...

Show Detail

How to get set of active slides in bxslider?

Was just integrating bxslider into my website and i have a requirement , where in i need the current set of active /visible images in the slider, see an example of bxslide HERE. The jQuery init co...

Show Detail

bxslider - slides not being refreshed properly with JQuery

I have a carousel that has different HTML messages and we want the users to "slide" through the messages so they view each set of slides. We are using bxSlider and everything is working fine until I

Show Detail

bxslider remove gap between slides and thumbnail pager

I am using bxslider with a thumbnail pager. It all works fine, but there is a large space between the slides and the thumbnails (about an inch). I can't find where to reduce the size of this gap. H...

Show Detail

BxSlider min and max slides not working

I have about 10-15 slides in the . Max slides is 4, but only 1 slide is showned. When the page loads, the slider "flashes", and show 4 slides, but after that, one slide is displayed again. Whats ...

Show Detail