0

だから私は自分で作った私のワードプレスページにこの非常にシンプルな(そしておそらく推奨される方法で作られていない)画像スライダーを持っています. 私の問題は、画像がなくなると、空白などがスライドすることです。最初からスライドを開始するか、最後の画像でスライドを停止します。これが私のコードです: HTML:

<div id="gallery-wrap">
   <div id="gallery">
      <img class="galleryimage" src="http://materiaalit.kotisivut.name/sivustokuvat/ccc.PNG" alt="" />
      <img class="galleryimage2"  src="http://materiaalit.kotisivut.name/sivustokuvat/coverline.PNG" alt="" />
      <img class="galleryimage3"  src="http://materiaalit.kotisivut.name/sivustokuvat/ccc.PNG" alt="" />
      <img class="galleryimage4"  src="http://materiaalit.kotisivut.name/sivustokuvat/coverline.PNG" alt="" />
   </div>
    <div id="gallery-controls">
      <a id="gallery-prev" href="#"><img alt="" /> </a>
      <a id="gallery-next" href="#"><img alt="" /></a></div>
    </div>
</div>

CSS:

#gallery-wrap{margin: 0 auto; overflow: hidden; width: 100%; position: relative; height:300px; border:1px solid black; border-radius:6px; z-index:3;}
#gallery{position: relative; left: 0; top: 0; width:100%;}
.galleryimage{position:absolute; width:100%; height:300px; top:0px;}
.galleryimage2{position:absolute; width:100%; height:300px; left:100%;top:0px;}
.galleryimage3{position:absolute; width:100%; height:300px; left:200%;top:0px;}
.galleryimage4{position:absolute; width:100%; height:300px; left:300%;top:0px;}

#gallery-controls{width: 100%; z-index:4;}
#gallery-prev{position:absolute; left:0px; top:0px; width:50%; height:300px; }
#gallery-next{position:absolute; right:0px; top:0px;  width:50%; height:300px;}

そしてjs/jquery

var position = 1; // you always start at the first image?
$(document).ready(function()
{
  $("#gallery-prev").click(function(){

    var nr_of_img = $('img', $('#gallery')).length;

    if (position == 1)
    { 
      // move all the way to the last image
      position = nr_of_img;
    }
    else
    {$("#gallery").animate({"left": "+=100%"}, "slow");
      // move to the previous image
      position--;
    }
  });

  $("#gallery-next").click(function(){

    var nr_of_img = $('img', $('#gallery')).length;

    if (position == nr_of_img)
    { 
      // move all the way to the first image
      position = 1;
    }
    else
    {$("#gallery").animate({"left": "-=100%"}, "slow");
      // move to the previous image
      position++;
    }
  });
});

ご覧のとおり、変数に何を入れるかを考えています。スクリプトは、イメージがなくなったことをどのように認識しますか? ご覧のとおり、画像は完全に配置されています。これが、すべての画像を同じ水平線に合わせる最も簡単な方法でした。誰かがこれを実際に見たい場合: http://wordpress.kotisivut.name/

4

2 に答える 2

0

あなたはjavascriptを通してフォルダ内のこのカウント数のファイルを読むことができます

  1. PHPを使用すると、ファイル数を次のように設定できます。

    $directory = "../images/team/harry/";
    if (glob($directory . "*.jpg") != false)
    {
     $filecount = count(glob($directory . "*.jpg"));
     echo $filecount;
    }
    else
    {
     echo 0;
    }
    
于 2012-07-24T10:53:34.407 に答える
0

スライダー内の画像の数を数えてみませんか...

var nr_of_img = $('img', $('#gallery')).length;

次に、左から右への移動回数などを数えて、画像が不足しているかどうかを確認できます。

[編集]

まず第一に、if ステートメントが間違った場所にあります。イベント関数で if 文を実行したい。

これは、あなたがこのようなことをすることを意味します

var position = 1; // you always start at the first image?
$(document).ready(function()
{
  $("#gallery-prev").click(function(){
    var nr_of_img = $('img', $('#gallery')).length;

    if (position == 1)
    {
      // move all the way to the last image
      position = nr_of_img;
    }
    else
    {
      // move to the previous image
      position--;
    }
  });

  $("#gallery-next").click(function(){
    var nr_of_img = $('img', $('#gallery')).length;

    if (position == nr_of_img)
    {
      // move all the way to the first image
      position = 1;
    }
    else
    {
      // move to the previous image
      position++;
    }
  });
});
于 2012-07-24T10:56:44.097 に答える