Search code examples
javascriptjquerysliderzurb-foundationorbit

Foundation 4: Orbit: Initialitation after page loading & Ajax: Reinitialization


(1) I’ve got an project and I want to use the integrated slider from Foundation 4 (Orbit). My problem is, that I only want to initialize the slider (or to start the plugin) when the browser have a specific orientation. So for my problem I need an method to start or to initialize the plugin myself.

I tried something like this:

$(document).foundation('orbit', 'start‘); 

But first it starts right from the beginning of page loading and second it doesn’t start with the code line I showed you.

(2) Just one more question: On top of the question above, can I load Orbit content Slides with Ajax or do I need another solution for this? I think I need something like reinitializing-function of the slider?


Solution

  • I only want to initialize the slider (or to start the plugin) when the browser have a specific orientation

    You need to do something like this:

    if (screen.innerWidth > screen.innerHeight) {
        // start orbit when the device is on a landscape mode
        $(document).foundation('orbit').init();
    }
    

    can I load Orbit content Slides with Ajax

    Sure you can, just reinitialize orbit after you added your content. Something like:

    $("#yourSlider").append('<li><img src="url_of_the_image" /></li>');
    $(document).foundation('orbit').init();