Give help. Get help.

  • # December 31, 2016 at 1:36 pm

    I was trying to create a code of image gallery with just Javascript without plugin, but I didn’t find a tutorial that have thumbnails and when click substitute large image.

    I tried with jquery, how can I change to javascript?

    $('.thumb').click(function(event) {
                currentIndex = $(this).attr('data-indx');
                $('#tela img').remove();
                $('<img />')
                .attr('src', $(this).parent().attr('href'))
                .attr('alt', $(this).attr('alt'))
                .css('opacity', '0.3')
                .animate({opacity: 1 }, 2000);
     function mostraImagem() {
      var item = $(items).eq(currentIndex);
      $('#tela img')
      .attr('src', $(item).parent().attr('href'))
      .attr('alt', $(this).attr('alt'))
      .css('opacity', '0.3')
      .animate({opacity: 1 }, 2000);
     $('.next').click(function() {
          currentIndex ++;
          if (currentIndex > itemAmt - 1) {
                currentIndex = 0;
    $('.prev').click(function() {
      currentIndex -= 1;
      if (currentIndex < 0) {
        currentIndex = itemAmt - 1;
      function cycleItems() {
      var item = $('div .thumb').attr('data', currentIndex);
    /*var autoSlide = setInterval(function() {
      currentIndex += 1;
      if (currentIndex > itemAmt - 1) {
        currentIndex = 0;
    }, 3000);
    # January 1, 2017 at 10:00 am

    Could you use something like baguetteBox ?

    # January 1, 2017 at 4:13 pm

    No I need to create without plugins.

    # January 2, 2017 at 3:52 am

    The next best thing, when you can’t find a tutorial, is to look for a simple example, like PhotoViewerJS, and study the source code. Someone like Chris Ferdinandi is making tutorials nowadays, like Christian Heilmann also used to do. Others as well anyone? Maybe follow geeks like these on Github and social-media to see what they are up to.

    # January 2, 2017 at 7:52 am

    I have one in plain Javascript, it is even slightly animated:-)

    I am adding comments to the JS, to make it understandable.

    # January 2, 2017 at 10:13 am

    Thank you both for the examples. I am learning and trying to create my own code.

    I will study the examples.

    I found example that looks like very simple but some details maybe are outdated:

    Some tutorial use the sintaxe new image, why? Sometimes I Just need to understand what mean some lines of code do to make sense.

    # January 2, 2017 at 10:20 am

    There’s also this tutorial by Jeremy Keith, also quite old, but it will still work. I believe in his book “Dom Scripting” there is a more elaborate example of this.

    # January 2, 2017 at 10:40 am

    Some tutorial use the sintaxe new image, why?

    This can be handy if you have a lot of images, you can then create them on the fly. Not necessary if you have put them in the HTML markup already.

    Note that document.images in your example will select all images on the entire page…

    Maybe you could create a demo on Codepen when you’ve decided on a script. It’ll be easier for us to help out. The code you initially posted will need quite a few changes to make it vanilla JS, especially the first part.

    # January 2, 2017 at 12:05 pm

    Thanks, I will look for the book and post a codepen link.

    One last question:

    Almost alI tutorials about image gallery the function onclick is equal the function “name (number or path file)”.

    If i don’t know the number or the path, how can pass the code if it’s dynamic?

    # January 2, 2017 at 1:14 pm

    Could you post an example of the actual code? It looks like you’re describing inline script, which is better not used. Any dynamic input should be easily converted in an external script, the last line you wrote is therefore somewhat confusing.

    # January 23, 2018 at 10:49 am

    Hi, after a lot of research I could create a thumbnail gallery with slider, unfortunally I didn’t get the job, but I learn something:

    What I don’t understand it’s that code:

     counter = (n + imgs.length) % imgs.length;

    This week a youtube channel that I follow publish a solution much better, but doesn’t have the slider that was a requirement. If someone needed:

    The book “Dom Scripting” is good but it’s outdated.

    # January 23, 2018 at 11:30 am

    The line you posted uses the modulo operator %. It’s handy to reduce a number to a remainder, after subtracting a multitude of the number that follows. So for example:

    17 % 3 = 2

    Because the maximum multitude of 3 that can be subtracted is 3 x 5 = 15, the remainder then is 2. In the script, it keeps the number that will be matched with an image between zero and the amount of images available (minus one because they are zero indexed).

    Not sure that helps. Hard to explain.

    # January 23, 2018 at 12:10 pm

    Thank you, I asked because I tried with imgs.length -1 and I was getting the error, because was calculating wrong and this calculation solve all.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.