javascript - initialize owl carousel on click function of tab -
i using tab structure owl slider , title user wanted unique url of each tab clicked, changed click function. here, unable process slider.it won't work. 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); })
how solve this? help/suggestions welcome.
found solution problem. carousel issue due tab hide , show. added timeout function initializing carousel.
$(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); })
Comments
Post a Comment