简体   繁体   中英

Bootstrap carousel: changing jquery slides to bootstrap caroulsel and binding a slide function

I started applying the bootstrap on my site. I need to change this following script to work on bootstrap carousel

        $(function(){
            // Set starting slide to 1
            var startSlide = 1;
            // Get slide number if it exists
            if (window.location.hash) {
                alert('hash'+window.location.hash);
                startSlide = window.location.hash.replace('#','');
                alert('startslide'+startSlide);
            }
            // Initialize Slides
            $('#slides2').slides({
                preload: true,
                preloadImage: 'img/loading.gif',
                generatePagination: true,
                play: 0,
                pause: 2500, 
                hoverPause: true,
                currentClass: 'current',
                // Get the starting slide
                start: {$startNumb},
                animationComplete: function(current){
                    // Set the slide number as a hash
                    window.location.hash = '#' + current;
                    alert('windows hash'+window.location.hash);
                    alert('current'+current);
                    $('#activeSlideIndex').val(current);
                    $('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
                    $('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][0]);
                    $('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][1]);
                }
            });

I've tried something like this but it is not working. I don't know where is that current variable getting its value and how window.location.hash work

    $(function(){
        // Set starting slide to 1  
        var startSlide = 1;
        // Get slide number if it exists
        if (window.location.hash) {
            startSlide = window.location.hash.replace('#','');
        }
        $('#myCarousel').bind('slide',function(current){ 
            window.location.hash = '#' + current;
            $('#activeSlideIndex').val(current);
            $('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
            $('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][0]);
            $('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][1]);
    });     

    }); 

found a solution.This one gets the current index of the carousel

$('#myCarousel').bind('slid',function(e){  
            var current =  $(".active", e.target).index()+1;   
                $('#activeSlideIndex').val(current);
                $('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
                $('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][0]);
                $('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite">&nbsp;</b> ' + voteCountArray[current-1][1]);
        });  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM