0

合計 10 枚の 5 枚の画像が 2 行で構成された画像ギャラリーがあります。私は20枚の画像を持ち、ユーザーが次のボタンを押すとギャラリーが次の10枚の画像に移動する前に、ユーザーが前の10枚の画像に移動しようとしています。私の人生では、前と次のボタンが機能しない理由がわかりません。

jQuery:

var $item = $('div.folder'), //Cache your DOM selector
       visible = 5, //Set the number of items that will be visible
       index = 0, //Starting index
       endIndex = ($item.length / visible) - 1; //End index

   $('div#arrowR-spring').click(function () {
       if (index < endIndex) {
           index++;
           $item.animate({
               'left': '-=315px'
           });
       } else {
           index = 0;
           $item.animate({
               'left': '+=' + (315 * endIndex) + 'px'
           });
       }
   });

   $('div#arrowL-spring').click(function () {
       if (index > 0) {
           index--;
           $item.animate({
               'left': '+=315px'
           });
       } else {
           index = endIndex;
           $item.animate({
               'left': '-=' + (315 * endIndex) + 'px'
           });
       }
   });

これが私が現在持っているものです: link to my fiddle . どんな助けでも大歓迎です!

4

2 に答える 2

0

HTML コードで jsfiddle が 10 項目しかないことがわかります。しかし、HTML に存在しない残りの 10 項目のインデックスを変更しようとしています。もう一度 HTML コードを見て、そこに 20 個の項目があることを確認してください。

于 2013-03-12T04:07:32.037 に答える