Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

jquery - How to get bootstrap carousel next image src?

i want to know how to get the next and previous image src of bootstrap carousel and display that in a src img tag with class previmage and nextimage.

Thanks

EDIT:

here is my html:

<div id="slideshow-homepage" class="carousel slide swiper-container" data-ride="carousel" data-interval="5000">

  <!-- Slides Container -->
  <div class="carousel-inner swiper-wrapper">

    <div class="item active swiper-slide">
     <a href="#" title="">
        <img src="" alt="" class="img-responsive">
     </a>
      <div class="caption">

        <div class="text"></div>

      </div>
    </div>
    <div class="item swiper-slide">
      <img src="" alt="" class="img-responsive">
      <div class="caption">

        <div class="text"></div>
      </div>
    </div>
    <div class="item swiper-slide">
      <img src="" alt="" class="img-responsive">
      <div class="caption">

        <div class="text"> </div>
      </div>
    </div>

  </div>
<nav class="nav-diamond">
      <a class="prev leftButton" href="#slideshow-homepage" role="button" data-slide="prev">
        <span class="icon-wrap">
          <svg class="icon" width="28" height="28" viewBox="0 0 64 64">
          <svg width="64" height="64" viewBox="0 0 64 64">
    <path id="arrow-left-1" d="M46.077 55.738c0.858 0.867 0.858 2.266 0 3.133s-2.243 0.867-3.101 0l-25.056-25.302c-0.858-0.867-0.858-2.269 0-3.133l25.056-25.306c0.858-0.867 2.243-0.867 3.101 0s0.858 2.266 0 3.133l-22.848 23.738 22.848 23.738z" />
          </svg>
          </svg>
        </span>
        <div><img class="previmage" src="images/10.png" alt="Previous thumb"></div>
      </a>
      <a class="next rightButton" href="#slideshow-homepage" role="button" data-slide="next">
        <span class="icon-wrap"><svg class="icon" width="28" height="28" viewBox="0 0 64 64">
  <svg width="64" height="64" viewBox="0 0 64 64">
    <path id="arrow-right-1" d="M17.919 55.738c-0.858 0.867-0.858 2.266 0 3.133s2.243 0.867 3.101 0l25.056-25.302c0.858-0.867 0.858-2.269 0-3.133l-25.056-25.306c-0.858-0.867-2.243-0.867-3.101 0s-0.858 2.266 0 3.133l22.848 23.738-22.848 23.738z" />
  </svg>
        </svg></span>
        <div><img class="nextimage" src="images/7.png" alt="Next thumb"></div>
      </a>
    </nav>
</div><!-- /Slideshow Homepage -->

I am trying to apply the diamond effect that are in this site http://tympanus.net/Development/ArrowNavigationStyles/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Right, so here is a plunkr with corrected indentation: http://plnkr.co/edit/IdvC8YIgQBF6wuDAzbxU

To get the next image, assuming that you want to use jQuery and that the current image is the one with the class 'active':

$(document).ready(function () {

  function getNextAndPrev() {
    var activeSlide = $('.active');

    var nextImage, prevImage;

    if (activeSlide.next().length) {
      nextImage = activeSlide.next().find('img').attr('src')
    } else {
      nextImage = $('.carousel-inner').children().first().find('img').attr('src');
    }

    if (activeSlide.prev().length) {
      prevImage = activeSlide.prev().find('img').attr('src')
    } else {
      prevImage = $('.carousel-inner').children().last().find('img').attr('src');
    }

    $('.previmage').attr('src', prevImage);
    $('.nextimage').attr('src', nextImage);
  }

  getNextAndPrev();

  $('.next, .prev').on('click', getNextAndPrev);

});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...