1

I'm using Owl Carousel 2 and trying to make custom dots with text. The custom dots show up but nothing happens when you click them. I.e. when you click a dot it doesn't jump back to the appropriate slide, it just does nothing. How can I get the carousel the go to the appropriate slide when the custom dots are clicked?

The full code is here: https://codepen.io/anon/pen/ZqKaEZ

HTML:

<div class="owl-carousel owl-theme">
<div class="item" data-dot="<span>1</span>">
  <img src="https://placehold.it/100">
</div>
<div class="item" data-dot="<span>2</span>">
  <img src="https://placehold.it/100">
</div>
<div class="item" data-dot="<span>3</span>">
  <img src="https://placehold.it/100">
</div>
<div class="item" data-dot="<span>4</span>">
  <img src="https://placehold.it/100">
</div>

JS:

$(document).ready(function(){
  $(".owl-carousel").owlCarousel({
        autoplay: true,
        autoplayTimeout: 4000,
        dots: true,
        dotsData:true,
        loop: true,
        margin: 30,
        nav: false,
        center: false,
        items: 1
    });
});
Mia
  • 233
  • 4
  • 19

6 Answers6

3

Here is the code that worked:

$(document).ready(function(){
    let owl = $(".owl-carousel").owlCarousel({
        autoplay: false,
        autoplayTimeout: 2000,
        dots: true,
        dotsData:true,
        loop: true,
        margin: 30,
        nav: false,
        center: false,
        items: 1
    });

    $('.owl-dot').click(function() {
        owl.trigger('to.owl.carousel', [$(this).index(), 1000]);
    })
});
korwalskiy
  • 927
  • 12
  • 12
0
<div class="testimonial_slider owl-carousel owl-theme">
    <div class="item" data-dot="<img src='images/testimonial-1.jpg' alt='' class='img-fluid' />">
        <div class="testimonial-content text-center">
            <div class="testimonial-dec">
                <h4>Aklima The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections Bonorum et Malorum original.</h4>
            </div>
            <div class="testimonial-name mt-4">
                <p class="border-bottom d-inline-block"><span class="d-inline-block text-uppercase text-dark">AKLIMA</span>  - COO, AMERIMAR ENTERPRISES, INC.</p>
            </div>
        </div>
    </div>
    <div class="item" data-dot="<img src='images/testimonial-1.jpg' alt='' class='img-fluid' />">
        <div class="testimonial-content text-center">
            <div class="testimonial-dec">
                <h4>Aklima The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections Bonorum et Malorum original.</h4>
            </div>
            <div class="testimonial-name mt-4">
                <p class="border-bottom d-inline-block"><span class="d-inline-block text-uppercase text-dark">AKLIMA</span>  - COO, AMERIMAR ENTERPRISES, INC.</p>
            </div>
        </div>
    </div>
</div>

<script>

    $('.testimonial_slider').owlCarousel({
        loop:false,
        margin:32,
        nav:false,
        dots: true,
        items:1,
        mouseDrag: false,
        dotsData: true,
    })

</script>
Dilan
  • 2,610
  • 7
  • 23
  • 33
0
<div class="testimonial_slider owl-carousel owl-theme">
<div class="item" data-dot="<button><img src='images/testimonial-8.jpg' alt='' class='img-fluid' /></button>">
    <div class="testimonial-content text-center">
        <div class="testimonial-dec">
            <h4>Aklima The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections Bonorum et Malorum original.</h4>
        </div>
        <div class="testimonial-name mt-4">
            <p class="border-bottom d-inline-block"><span class="d-inline-block text-uppercase text-dark">AKLIMA</span>  - COO, AMERIMAR ENTERPRISES, INC.</p>
        </div>
    </div>
</div>
    $('.testimonial_slider').owlCarousel({
    loop:false,
    margin:32,
    nav:false,
    dots: true,
    items:1,
    mouseDrag: false,
    dotsData: true,
})
0

Remove dotsData: true, in js and width: inherit; height: inherit; from .owl-theme .owl-dots .owl-dot span in this codepen https://codepen.io/anon/pen/ZqKaEZ . It will work.

Rafee Shaik
  • 681
  • 4
  • 10
0

this is answer

$(document).ready(function(){
let owl = $(".owl-carousel").owlCarousel({
    autoplay: false,
    autoplayTimeout: 2000,
    dots: true,
    dotsData:true,
    loop: true,
    margin: 30,
    nav: false,
    center: false,
    items: 1
});

$('.owl-dot').click(function() {
    $('.owl-dot').trigger('to.owl.carousel', [$(this).index(), 1000]);
})

});

0

The solution:

I found it does work without adding extra jQuery code. You just need to follow the original HTML structure for the custom dot navigation. When using dotsData: true the script is working for a button tag, so simply re-insert the button tag in the data-dot.

For example:

<div class="item" data-dot="<button>Name</button>"><h4>Name</h4></div>

This renders your custom dot content as a button, and you are able to navigate these dots as you normally would.

Scopestyle
  • 643
  • 5
  • 18