简体   繁体   中英

onclick of 2nd image should become active (i.e. make a next() call)

I am displaying 2 images in a slider one beside another with next and previous icons. Not able to add one more scenario ie onclick of 2nd image in the slider should make a next() call and so on in flexslider.

Example: Slide#1 is active and Side#2 is semi active image, onclick of "Slide#2" semi-active image area it should become "active" and "Slide#3" should be semi active image and so on.

Demo JSFiddle: https://jsfiddle.net/pkuwhvqm/

HTML:

<div class="outerWideSlider">
<div class="wideSlider">
<div class="flexslider" data-startat="0">
  <ul class="slides">
    <li>
      <img alt="" src="https://www.solodev.com/assets/flexslider/slide1.jpg">
      <div class="text-caption">
        <div class="inner">
          <h2>Slide #1</h2>
          <p>This is the text for slide #1</p>
        </div>
      </div>
    </li>
    <li>
      <img alt="" src="https://www.solodev.com/assets/flexslider/slide2.jpg">
      <div class="text-caption">
        <div class="inner">
          <h2>Slide #2</h2>
          <p>This is the text for slide #1</p>
        </div>
      </div>
    </li>
    <li>
      <img alt="" src="https://www.solodev.com/assets/flexslider/slide3.jpg">
      <div class="text-caption">
        <div class="inner">
          <h2>Slide #3</h2>
          <p>This is the text for slide #1</p>
        </div>
      </div>
    </li>
  </ul>
</div>
 </div>
</div>

Javscript:

$(document).ready(function () {
$(".wideSlider").each(function () {
var $this = $(this);
var $slider = $this.find(".flexslider");
var startat = $slider.attr("data-startat");
if (startat = 0) {
}
$slider.flexslider({
  animation: 'slide',
  easing: 'linear', // // Default: swing   {NEW} String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported!
  // useCSS: false, // Default: true
  slideshow: false, // Default: True  //Boolean: Animate slider automatically
  slideshowSpeed: 7000, // Default: 7000 // Integer: Set the speed of the slideshow cycling, in milliseconds
  animationLoop: true, // Default: true
  startAt: startat,
  controlNav: false,
  directionNav: true,
  nextText: " ",
  prevText: " ",
  start: function (slider) {
    // $('.wideSlider .text-caption').fadeOut(100);
    // var $s = slider.slides.eq(slider.currentSlide);
    // $s.find('.text-caption').show();
  },
  before: function (slider) {
    // $('.wideSlider .text-caption').hide();
  },
  after: function (slider) {
    // var $s = slider.slides.eq(slider.currentSlide);
    // $s.find('.text-caption').show();
  }
});
 });
 })

Just add the below handler. https://jsfiddle.net/g1mteokv/

$("li").click(function(){
   if($(this).prev().hasClass("flex-active-slide")){
        $(".flex-next").click();
    }else if ($(this).next().hasClass("flex-active-slide")){
        $(".flex-prev").click();
    }
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM