2013-10-15 73 views
0

使用RequireJS使用skrollr和skrollrMenu时出现错误。这是我main.js文件:与RequireJS一起使用Skrollr和SkrollrMenu

require.config({ 
    paths: { 
     jquery: '../bower_components/jquery/jquery', 
     skrollr: '../bower_components/skrollr/src/skrollr', 
     skrollrMenu: '../bower_components/skrollr-menu/src/skrollr.menu' 
    }, 
    shim: { 
     skrollrMenu: { 
      deps: ['skrollr'] 
     } 
    } 
}); 

require(['app', 'jquery', 'skrollr', 'skrollrMenu'], function (app, $) { 
    'use strict'; 

    window.onload = function() { 
     var s = skrollr.init(); 

     console.log(s); 
     // //The options (second parameter) are all optional. The values shown are the default values. 
     skrollr.menu.init(s, { 
      //skrollr will smoothly animate to the new position using `animateTo`. 
      animate: true, 

      //The easing function to use. 
      easing: 'sqrt', 

      //How long the animation should take in ms. 
      duration: function(currentTop, targetTop) { 
       //By default, the duration is hardcoded at 500ms. 
       return 500; 

       //But you could calculate a value based on the current scroll position (`currentTop`) and the target scroll position (`targetTop`). 
       //return Math.abs(currentTop - targetTop) * 10; 
      }, 
     }); 
    } 
}); 

当我在skrollr.menu文件至此加载页面出现错误Uncaught TypeError: Cannot call method 'relativeToAbsolute' of undefined

targetTop = _skrollrInstance.relativeToAbsolute(scrollTarget, 'top', 'top'); 

然后后面的输出console.log(s)。这是否意味着skrollr.menu.initconsole.log(s)之前运行?

+0

你有没有试过[shim config](http://requirejs.org/docs/api.html#config-shim)?另请参阅:http://stackoverflow.com/questions/15471088/requirejs-why-and-when-to-use-shim-config – explunit

+0

@explunit我尝试了shim配置。我编辑了我的问题,包括它。但是,我仍然遇到同样的问题。 – xylar

回答

1

更新到skrollr-menu 0.1.6(我猜你正在运行0.1.5)。

+0

排序它,谢谢(还有skrollr)! – xylar

+0

哦,没有这个答案的人我会在几天内进行调试;)在项目中保持外部js库最新的最佳策略是什么? – Advanced

+0

@Advanced http://bower.io/,但skrollr不可通过bower atm使用 – Prinzhorn