0
votes

I need help with a jquery script, I want to change the img src path from image_1.jpg to image_2.jpg, image_3.jpg, .. in the div with id type_a_images. The number of images in the folder is completely random, so I need the script to check how many images are in the folder and set this number to maxValue in the slider script. What I want is a similar slider to the one in this page.

Can you help me with this? Thanks.

HTML

<div id="type_a_images">
  <p>
    <img src="../slider_images/type_a/image_1.jpg">
  </p>
</div>
<div id="type_a_slider"></div>

JQUERY

$(function() {
    $( "#type_a_slider" ).slider({
      value: 1,
      min: 0,
      max: maxValue,
      step: 1,

      slide: function( event, ui ) {

        ??????????;

      }
    });
  });
1
Actually you can't really count the number of the elements in the folder with JavaScript. Off course you could try to load images 1, 5 and 10 and if they all load try it further with higher numbers till you hit a number that doesn't load an image. But that would not be very performant and it would waist a lot of bandwidth. I would check the number of items Server side and inject it into the HTML or make an ajax request to an server side image counting script.Leo Gerber

1 Answers

0
votes

something like this should work to get the count of elements:

var maxValue = jQuery('#type_a_images > p > img').length;