Grow your CSS skills. Land your dream job.

AnythingSlider onInitialized bug?

  • # September 10, 2012 at 6:52 am

    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?

    # September 10, 2012 at 7:29 pm

    Hi Frantiq!

    It sounds like [this demo](http://jsfiddle.net/Mottie/ycUB6/34/) 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); }

    });​

    # September 11, 2012 at 2:45 am

    Thanks Mottie, that worked like a sharm :)

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".