How to dynamically load foundation orbit?

断了今生、忘了曾经 提交于 2019-12-12 02:54:53

问题


In my javascript, if the window is a specific width, add the data-orbit attribute to my intended slider. This fires on $(window).resize() and $(function(){}).

The condensed version...

   var ui = {
        mobile : function() {
            var i = 0;
            if($(window).width() <= 568) {
                this.resizeOffers();
            } else {
                this.mobileClear();
            }
        },
        resizeOffers : function() {
                $('#offers .inner').attr('data-orbit', "");

        },
        mobileClear : function() {
                $('#offers .inner').removeAttr('data-orbit');

        }
    }

Everything works great if you load the page while the window width falls into the condition. If you load the page with a normal window width, then resize to the media query, obviously orbit didn't load with the dom so there is no slider animation or dynamically added orbit dom elements.

My question is...

How can I have orbit manipulate the dom, after the document has loaded? Or is this not possible?

Thanks,
Seth


回答1:


Thinking about this you could load the orbit js using ajax then initiate it once the dom is ready.

 $(document).ready(function(){

   //load the orbit JS
   $.ajax({
     url: 'js/foundation/foundation.orbit.js',
     dataType: 'script',
     success: function(){
       //initiate orbit
       console.log('loaded');
       $(document).foundation('orbit');
     },
     async: false
   });

});



回答2:


Found out after the fact that if orbit is loaded, running ... $(document).foundation('orbit'); in my the js media query did the same as above, without any http requests.



来源:https://stackoverflow.com/questions/17111624/how-to-dynamically-load-foundation-orbit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!