0

我开始在我的网站上应用引导程序。我需要更改以下脚本以在引导轮播上工作

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

    }); 
4

1 回答 1

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]);
        });  
于 2013-07-22T16:55:18.553 回答