使用 RequireJS 使用 skrollr 和 skrollrMenu 时出现错误。这是我的 main.js 文件:
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;
},
});
}
});
当我加载页面Uncaught TypeError: Cannot call method 'relativeToAbsolute' of undefined
时,在 skrollr.menu 文件中出现错误:
targetTop = _skrollrInstance.relativeToAbsolute(scrollTarget, 'top', 'top');
然后是 的输出console.log(s)
。这是否意味着skrollr.menu.init
之前正在运行console.log(s)
?