我正在使用带有owl滑块和标题的标签结构,但由于用户想要点击每个标签的唯一网址,我将其更改为点击功能。在这里,我无法处理滑块。它只是不起作用。 HTML:
<ul id="myTab" class="nav nav-tabs">
<li class="active" id="chhimi-gurung">
<a href="#tab-0" data-toggle="tab" rel="chhimi-gurung">Chhimi Gurung</a>
</li>
<li class="" id="subha-shrestha">
<a href="#tab-1" data-toggle="tab" rel="subha-shrestha">Subha Shrestha </a>
</li>
</ul>
<div id="myTabContent" class="tab-content" >
<div class="tab-pane fade active in" id="tab-0">
<h3>Chhimi Gurung</h3>
<div class="owl-carousel team-image-slider" id="team-image-slider-0">
<img src="uploads/images/team/profile-4.jpg" alt="" />
<img src="uploads/images/team/profile-3.jpg" alt="" />
</div>
</div>
<div class="tab-pane fade" id="tab-1">
<h3>Subha Shrestha</h3>
<div class="owl-carousel team-image-slider" id="team-image-slider-1">
<img src="uploads/images/team/profile-1.jpg" alt="" />
<img src="uploads/images/team/profile-2.jpg" alt="" />
<img src="uploads/images/team/profile-3.jpg" alt="" />
</div>
</div>
</div>
JQUERY:
var $owl = $('.team-image-slider');
$(document).on("click", "ul#myTab li a", function() {
var slug = $(this).attr("rel");
var current_url = url.substring(0,url.lastIndexOf("/"));
var tabId = $(this).attr("href").split("-")[1];
$owl.trigger('destroy.owl.carousel');
$owl.html($owl.find('.owl-stage-outer').html()).removeClass('owl-loaded');
$("#team-image-slider-"+tabId).owlCarousel({
autoplay: true,
autoplayTimeout: 5000,
items: 1,
nav: true,
smartSpeed: 500,
});
history.pushState(null, null, current_url + '/' + slug);
})
我如何解决这个问题?欢迎任何帮助/建议。
答案 0 :(得分:1)
找到问题的解决方案。轮播问题是由于标签隐藏和显示。因此添加了用于初始化轮播的超时功能。
$(document).on("click", "ul#myTab li a", function() {
var slug = $(this).attr("rel");
var current_url = url.substring(0,url.lastIndexOf("/"));
var tabId = $(this).attr("href").split("-")[1];
setTimeout(function(){
$("#team-image-slider-"+tabId).owlCarousel({
autoplay: true,
autoplayTimeout: 5000,
items: 1,
nav: true,
smartSpeed: 500,
});
}, 200);
history.pushState(null, null, current_url + '/' + slug);
})