How to destroy/disable slider from ratchet?

171 Views Asked by At

I use ratchet.js to slider many images.

But now I want to click an element 'a'/'button' trigger the 'slider' method . And I want to destory browser method when we drag/touch page to left .It will turn to next tab .

Only allow people to jump by clicking on the button.

The html code like this:

<div class="slider" id="slider">
    <div class="slide-group">
        <div class="slide">
            <img width="100%" src="/mobile/images/guide/1.jpg">
        </div>
        <div class="slide" id="slide-2">
            <img width="100%" src="/mobile/images/guide/2.jpg">
        </div>
        <div class="slide" id="slide-3">
            <img width="100%" src="/mobile/images/guide/3.jpg">
        </div>
        <div class="slide" id="slide-4">
            <img width="100%" src="/mobile/images/guide/4.jpg">
        </div>
    </div>
</div>

I try to use code like this to solve this problem.

document.body.addEventListener('slide', function (e) {
    e.preventDefault();
    return false;
});

but it does not work ...

how to solve this problem ~~

2

There are 2 best solutions below

0
sky91 On BEST ANSWER

I just solved this problem by ratchet like this ..

 <div class="guide-content" id="guide">
    <div class="guide-tab active" id="slide-1">
        <img width="100%" src="/mobile/images/guide/1.jpg">
    </div>
    <div class="guide-tab" id="slide-2">
        <img width="100%" src="/mobile/images/guide/2.jpg">
    </div>
    <div class="guide-tab" id="slide-3">
        <img width="100%" src="/mobile/images/guide/3.jpg">
    </div>
    <div class="guide-tab" id="slide-4">
        <img width="100%" src="/mobile/images/guide/4.jpg">
    </div>
</div>

Then I used

window.location.href = "#slide-3";

Just like "../guide#slide-3" to show the next page/tab , and are not allowed to switch pages sliding by slide .

In fact, you can only use tabs to achieve this effect without ratchet.js .

0
alan0xd7 On

Here is slider source code: https://github.com/twbs/ratchet/blob/master/js/sliders.js

It looks the code is tied directly to touch events (touchstart/move/end), and it does not provide functions for manually controlling the slides.

This means it would be very difficult do what you want with Ratchet's built-in slider, so it is best if you use something else for the slider.