2016-09-14 10 views
1

私はこのウェブページでカルーセルを持っていますhttps://stfn.herokuapp.comそれはほぼ完璧に動作し、中央にあるメイン(アクティブ)アイテムのみです。リダイレクトするはずです)jsファイルとインデックスの両方にリンクを追加しようとしましたが、誰かがヒントを得た問題を解決しませんでしたか?Jqueryカルーセルがアクティブなアイテムをクリックしてもリダイレクトされません

[編集]

はそれをやった、質問をする前に、最新のビルドをアップロードし忘れました。だから私は、index.htmlのimgにタグを追加しました。それはどちらもうまくいかないようです。ご覧のように、ここでは、コードのスニペットが

$('.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" 
     } 
    } 

}); 

JSファイルからリダイレクトするためだ、すべての要素がそれに割り当てられたインデックスを持っており、それが特定のページに切り替えることができます。アクティブ項目のインデックス番号は0ですが、他の項目と同じようには機能していません。

+0

いくつかのコードを示します。もちろん、何もしません。 'img'にはリンクがありません。 –

+0

ああ、最新のビルドをアップロードするのを忘れた。また、リダイレクトを担当するコードを追加しました。 –

+0

'goToLink' fnはひどいです。 :Dリンク/ページを配列に入れ、 'document.location.href = linkArray [currentIndex]'を呼び出してください –

答えて

1

if (currentIndex != index){ < - このチェックは両方ともゼロであるため、このチェックは偽です。

チェックが同じであれば、それはあなたが他を必要とし、後藤メソッドを呼び出して何も

もしません。

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

ありがとうシェフ、それはとてもシンプルだったと信じられない.. –

関連する問題