treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] AnythingSlider onInitialized bug?

  • Hi.

    I have a slider where every single slide has a (hidden) div with text in it. On "onSlideComplete" I switch text in a div outside of the actual slider by $('#slider .activePage .caption').html().

    I want to do the same thing on "onInitialized". onInitialized is supposed to be "Callback when the plugin finished initializing".

    But it's not working. The class "activePage" is not set on onInitialized. BUT here's the strange thing: if I add a setTimeout(function () { My code }, 1); it works. Am I doing something wrong with the callback or is this a bug?

  • Hi Frantiq!

    It sounds like this demo might be doing what you want. I wouldn't recommend using the activePage class since it isn't added until have the slide has completed animation.

    var updateCaption = function(slider){
        var cap = slider.$currentPage.find('.caption').html();
        $('#current-caption')
            .html(cap)
            .fadeIn(200);
    };
    
    $('#slider').anythingSlider({
    
        // *********** Callbacks ***********
        // Callback when the plugin finished initializing
        onInitialized: function(e, slider) { updateCaption(slider); },
    
        // Callback before slide animates
        onSlideBegin: function(e, slider) {
            $('#current-caption').fadeOut(200);
        },
    
        // Callback when slide completes - no event variable!
        onSlideComplete: function(slider) { updateCaption(slider); }
    
    });​
    
  • Thanks Mottie, that worked like a sharm :)