0

在我的 javascript 中,如果窗口是特定宽度,则将该data-orbit属性添加到我想要的滑块中。$(window).resize()这会在和上触发$(function(){})

精简版...

   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');

        }
    }

如果您在窗口宽度符合条件的情况下加载页面,一切都会很好。如果您以正常的窗口宽度加载页面,然后调整媒体查询的大小,显然轨道没有与 dom 一起加载,因此没有滑块动画或动态添加的轨道 dom 元素。

我的问题是...

加载文档后,如何让轨道操纵 dom?或者这是不可能的?

谢谢,
赛斯

4

2 回答 2

3

考虑到这一点,您可以使用 ajax 加载轨道 js,然后在 dom 准备好后启动它。

 $(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
   });

});
于 2013-06-14T16:02:05.813 回答
0

发现如果加载了轨道,运行... $(document).foundation('orbit'); 在我的 js 媒体查询中与上面相同,没有任何 http 请求。

于 2013-06-14T18:06:25.310 回答