点击活动项目的Jquery轮播没有重定向

时间:2016-09-14 12:07:12

标签: javascript jquery carousel

我在这个网页https://stfn.herokuapp.com中有一个旋转木马,它几乎完美,只有主要(活动)项目,它位于中心,一旦它没有做任何事情&#39 ; s点击(它应该重定向)我试图在js文件和索引中添加链接,但没有解决任何人得到提示的问题?

[编辑]

忘记在提出问题之前上传最新的版本,就这样做了。所以我在index.html中为img添加了一个标签,但这似乎也没有用。这是用于从js文件重定向的代码片段

    $('.carousel .item').click(function(e) {
        var index = $(this).index('li');
        carousel.cycleActiveTo(index);
        // song3();
        e.preventDefault();

        if ( currentIndex != index ){
            var difference;

            if ( currentIndex == 0 && index >= 5 ){
                difference = (index - currentIndex) - 13;
            } else {
                difference = index - currentIndex;
            }

            difference = Math.abs(difference);
            delay = difference * options.duration;
            currentIndex = index;

            console.log(delay);

            setTimeout( goToLink, delay );
        }
    });

    goToLink = function() {
        if (currentIndex == 0) {
            // console.log("works:");
            document.location.href = "about.html"
        }
        if (currentIndex == 1) {
            document.location.href = "blog.html"
        }
        else if (currentIndex == 2) {
            document.location.href = "collection.html"
        }
        else if (currentIndex == 3) {
            document.location.href = "shop.html"
        }
        else if (currentIndex == 4) {
            // alert("ABOUT2");
            document.location.href = "about.html"
        }
        else if (currentIndex == 5) {
            document.location.href = "blog.html"
        }
        else if (currentIndex == 6) {
            document.location.href = "collection.html"
        }
        else if (currentIndex == 7) {
            document.location.href = "contact.html"
        }
        else if (currentIndex == 8) {
            document.location.href = "shop.html"
        }
        else if (currentIndex == 9) {
            document.location.href = "contact.html"
        }
        else if (currentIndex == 0) {
            document.location.href = "about.html"
        }
    }

});

如您所见,每个元素都分配了一个索引,并允许切换到特定页面。活动项目的索引编号为0,但它似乎不像其他项目那样工作

1 个答案:

答案 0 :(得分:1)

if ( currentIndex != index ){< - 此检查为假,因为两者均为零。

因此,如果支票相等则无效

你需要一个else并调用goto方法。

if ( currentIndex != index ){ 
   ... the code ...
} else {
    goToLink();
}