Search code examples
javascriptjquerygalleria

galleria - run a JavaScript function everytime picture is changed


I am trying to find in the Galleria JavaScript file a place where I tell it to run a JavaScript function every time the current picture is changed (prev, next, or clicking on a thumbnail)

Does anyone with experience with galleria have any ideas? http://galleria.io/


Solution

  • When you set up your Gallery bind to the image function and you will receive the event every time the image changes. I use it to load text into another area of my page like so.

    Galleria.ready(function() { this.bind("image", function(e) { $("#text_div").text(arrayOfText[e.index]); }); });

    To make sure you have things setup correctly use it like this,

    Galleria.loadTheme('galleria/themes/kscreates/galleria.classic.js'); Galleria.configure(); Galleria.ready(function() { this.bind("image", function(e) { console.log(e.index); }); }); Galleria.run('#galleria');

    and have a look in your Safari console and you will see the index of the currently displayed image.

    Hope this helps.