[英]Bootstrap Carousel Transitions and Prev/Next Buttons Not Working
[英]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.