Search code examples
jqueryresponsive-slides

responsiveslides.js - get current slide


Need to get the 'data-number' value from the current slide that is active in the slider. I want to use this value to show/hide additional info in another div of the page. Or if there is some other way other than adding a specific 'data-number' values let me know - I saw nothing in the doc which returning the slide number.

I know I can use the 'after' callback to then do what I want, but not sure how I can go about getting this value in the first place.

<div class="row">
    <div class="col-md-12">
        <ul class="rslides" id="slider1">
            <li data-number="1">
                <img src="/user-data/2/screenshots/demo21.jpg" alt="">
            </li>
            <li data-number="2">
                <img src="/user-data/2/screenshots/demo22.jpg" alt="">
            </li>
            <li data-number="3">
                <img src="/user-data/2/screenshots/demo23.jpg" alt="">
            </li>
            <li data-number="4">
                <img src="/user-data/2/screenshots/demo24.jpg" alt="">
            </li>
            <li data-number="5">
                <img src="/user-data/2/screenshots/demo25.jpg" alt="">
            </li>
        </ul>               
    </div>
</div>

$("#slider1").responsiveSlides({
    auto: false,             // Boolean: Animate automatically, true or false
    speed: 500,            // Integer: Speed of the transition, in milliseconds
    timeout: 4000,          // Integer: Time between slide transitions, in milliseconds
    pager: true,           // Boolean: Show pager, true or false
    nav: true,             // Boolean: Show navigation, true or false
    random: false,          // Boolean: Randomize the order of the slides, true or false
    pause: false,           // Boolean: Pause on hover, true or false
    pauseControls: true,    // Boolean: Pause when hovering controls, true or false
    prevText: "Previous",   // String: Text for the "previous" button
    nextText: "Next",       // String: Text for the "next" button
    maxwidth: "",           // Integer: Max-width of the slideshow, in pixels
    navContainer: "",       // Selector: Where controls should be appended to, default is after the 'ul'
    manualControls: "",     // Selector: Declare custom pager navigation
    namespace: "centered-btns",   // String: Change the default namespace used
    before: function(){},   // Function: Before callback
    after: function(){}     // Function: After callback
}); 

Solution

  • No need to add a data attribute to the list. You can take the index of the current slide like this:

    $("#slider1").responsiveSlides({
        after: function(i){
            // i is equal to the index of the current active slide
        // Your code here
        }
    );