Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I stop javascript php gallery at last or first image?
    text
    copied!<p>I have a simple jquery and javascript image gallery that uses php to gather images and put them in li tags. The gallery works (almost) and will go left and right through the images, but I cannot get them to stop going right at the end and left on the first, they just keep scrolling through nothing. My .js code looks like this:</p> <pre><code>var currentImage = 1; var numImages = 0; $(document).ready( function(){ $('.rightbtn').click(function(){ moveLeft(); }); $('.leftbtn').click(function(){ moveRight(); }); $('.gallery-li').each(function(){ numImages++; }); }); function moveLeft() { if ( currentImage &lt; numImages ) { $('.gallery-ul').animate( { 'marginLeft' : '-=600px' } , 500, 'swing' ); $currentImage++; } if ( currentImage &gt; numImages ) { $('.rightbtn').css('display' , 'none'); } } function moveRight() { if ( currentImage = 1 ) { $('.gallery-ul').animate( { 'marginLeft' : '+=600px' } , 500, 'swing' ); $currentImage--; } if ( currentImage &lt; 1 ) { $('.leftbtn').css('display' , 'none'); } } </code></pre> <p>And my .php looks like this:</p> <pre><code> &lt;ul class="gallery-ul"&gt; &lt;?php $files = glob("pics/interior/*.*"); for ($i=1; $i&lt;count($files); $i++) { $num = $files[$i]; echo '&lt;li class="gallery-li"&gt;&lt;img src="'.$num.'" class="gallery-img"/&gt;&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; </code></pre> <p>Can someone PLEASE tell me what I'm doing wrong?</p> <p>I have this already on server at <a href="http://north49builders.com/gallery1.php" rel="nofollow">http://north49builders.com/gallery1.php</a> if you want to see what I'm talking about. </p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload