Bootstrap轮播:将jquery幻灯片更改为bootstrap caroulsel并绑定滑动功能

时间:2013-07-22 05:07:53

标签: javascript twitter-bootstrap

我开始在我的网站上应用引导程序。 我需要更改以下脚本以使用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]);
                }
            });

我尝试过类似的东西,但它没有用。  我不知道current变量在哪里获得它的价值以及window.location.hash如何工作

    $(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]);
    });     

    }); 

1 个答案:

答案 0 :(得分:0)

找到了一个解决方案。这个获得了旋转木马的当前索引

$('#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]);
        });