responsiveslides.js - get current slide

旧巷老猫 提交于 2019-12-11 21:24:00

问题


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
}); 

回答1:


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
    }
);



回答2:


You can use the following code to get the number you want:

$('.rslides1_on').data('number');

Or

$('.rslides1_on').index()


来源:https://stackoverflow.com/questions/23815515/responsiveslides-js-get-current-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!