我在这个网页中有一个轮播https://stfn.herokuapp.com它工作得几乎完美,只有主要(事件)项目位于中心,单击后不会执行任何操作(应该重定向)我尝试在 js 文件和索引中添加链接,但是没有解决问题,有人有提示吗?
[编辑]
在提问之前忘记上传最新版本,只是这样做了。所以我在index.html中的img中添加了一个a标签,但这似乎也不起作用。这是从 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,但它似乎不像其他项目那样工作
最佳答案
if ( currentIndex != index ){
<-- 此检查为 false,因为两者都为零。
因此,如果检查相等,则不会执行任何操作
您需要一个 else 并调用 goto 方法。
if ( currentIndex != index ){
... the code ...
} else {
goToLink();
}
关于javascript - Jquery 轮播点击事件项目不会重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39490043/