繁体   English   中英

轮播下一个/上一个按钮不起作用

[英]carousel next / prev buttons not working

我正在尝试从https://codepen.io/webcane/pen/lHGJf实现以下灯箱旋转木马,直到我尝试旋转木马上的上一个和下一个按钮不起作用(键盘上的向左和向右按钮可以工作)。

  // Hidden gallery
  /* activate the carousel */
  $("#modal-carousel").carousel({interval:false});

  /* change modal title when slide changes */
  $("#modal-carousel").on("slid.bs.carousel", function() {
    $(".modal-title")
    .html($(this)
    .find(".active img")
    .attr("title"));
  });

  /* when clicking a thumbnail */
  $(".row .service-icon").click(function() {
    var content = $(".carousel-inner");
    var title = $(".modal-title");

    content.empty();  
    title.empty();

    var id = this.id;  
    var repo = $("#img-repo .item");
    var repoCopy = repo.filter("#" + id).clone();
    var active = repoCopy.first();

    active.addClass("active");
    title.html(active.find("img").attr("title"));
    content.append(repoCopy);

    // show the modal
    $("#modal-gallery").modal("show");
  });

查看完我的js文件的其余部分之后,我发现主题附带的以下代码正在影响按钮,因为在我注释掉这段代码后,轮播按钮可以正常工作。

// Smooth scroll on page hash links
  $('a[href*="#"]:not([href="#"])').on('click', function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
          var target = $(this.hash);
          if (target.length) {

              var top_space = 0;

              if( $('#header').length ) {
                top_space = $('#header').outerHeight();
              }

              $('html, body').animate({
                  scrollTop: target.offset().top - top_space
              }, 1500, 'easeInOutExpo');

              if ( $(this).parents('.nav-menu').length ) {
                $('.nav-menu .menu-active').removeClass('menu-active');
                $(this).closest('li').addClass('menu-active');
              }

              if ( $('body').hasClass('mobile-nav-active') ) {
                  $('body').removeClass('mobile-nav-active');
                  $('#mobile-nav-toggle i').toggleClass('fa-times fa-bars');
                  $('#mobile-body-overly').fadeOut();
              }

              return false;
          }
      }
  });

以下是我的轮播按钮的html。 我猜想在href =“#modal-carousel”上滚动代码平滑,导致它无法正常工作。

<a class="carousel-control left" href="#modal-carousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="carousel-control right" href="#modal-carousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>

是否有任何解决方法,以便我可以同时使用两个功能?

通过添加解决问题

:not([href="#modal-carousel"])

$('a[href*="#"]:not([href="#"])')

因此它将忽略#modal-carousel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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