0

I'm using Jquery and Scrollmagic I have the following:

var slides = $("section.panel");

    for (var i=0; i<slides.length; i++) {
        var scene = new ScrollMagic.Scene({
                triggerElement: slides[i]
            })
            .setPin(slides[i])
            .addIndicators()
            .addTo(controller)
            .on("enter", function (event) {
                console.log(i);
            }); 
    }

console.log(i) is giving me 8 every time, for every scene, i'd like it to give me the number of the scene I get into.

Aschab
  • 1,378
  • 2
  • 14
  • 31
  • This will probably get closed. But you need a closure. Or wrap inner loop code in a function outside the loop with a parameter for the index. – Joe Oct 21 '16 at 00:04
  • you might be able to move the `var i=0` declaration outside of the loop to global scope – bassxzero Oct 21 '16 at 00:08

0 Answers0