简体   繁体   English

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

[英]carousel next / prev buttons not working

I am trying to implement the following lightbox carousel from https://codepen.io/webcane/pen/lHGJf Things was working fine until i tried the previous and next button on the carousel doesn't work (Left and Right button on keyboard do work though). 我正在尝试从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");
  });

After looking at the rest of my js file, I discovered that the following code that came along with the theme was affecting the buttons, as the carousel buttons works fine after i commented out this block of code. 查看完我的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;
          }
      }
  });

Below is the html for my carousel buttons. 以下是我的轮播按钮的html。 I am guessing that the smooth scrolling code is picking up on the href="#modal-carousel" causing it not to work. 我猜想在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>

Is there any workaround to this so that I can have both features working together? 是否有任何解决方法,以便我可以同时使用两个功能?

Fixed the problem by adding 通过添加解决问题

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

to

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

so that it would ignore #modal-carousel 因此它将忽略#modal-carousel

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

相关问题 Bootstrap Carousel Transitions 和 Prev/Next 按钮不起作用 - Bootstrap Carousel Transitions and Prev/Next Buttons Not Working 轮播的下一个和上一个按钮中的错误 - bug in next and prev buttons of carousel 轮播下一个和上一个按钮不起作用 - Carousel next and prev button not working Bootstrap 4轮播下一个和上一个按钮在一个页面上不起作用,但在其他页面上工作正常 - Bootstrap 4 carousel next and prev buttons are not working on one page but works fine on other 使用轮播等下一个和上一个按钮创建菜单列表 - Creating menu list with next and prev buttons like carousel 如何在 flexbox 轮播中间正确设置 position 上一个和下一个按钮? - How to correctly position prev and next buttons at the middle of flexbox carousel? Next 和 Prev 按钮不适用于多个日历 - Next and Prev buttons not working with multiple calendars Flickity轮播:在自定义div中包装上一个和下一个按钮 - Flickity carousel: Wrap prev and next buttons inside a custom div 带模式上一个/下一个按钮的图像滑块不起作用? - Image slider with modal prev/next buttons not working? Bootstrap轮播Slider活动类和“下一个/上一个”按钮不起作用 - Bootstrap carousel Slider active class and next/prev button not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM