我在主干应用程序中遇到这种滑动功能问题。当我尝试将Hammer.js添加到HEAD时出现错误:
Uncaught TypeError: Object [object Array] has no method 'addEventListener' hammer.min.js:7
您是否知道除Hammer.js之外的其他JavaScript,并且不依赖于jQuery在骨干网中正常工作?
我的头
<head>
<meta charset="utf-8">
<title>Backbone App</title>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<script data-main="js/main" src="js/libs/require/require.js"></script>
<script src="js/libs/utils.js"></script>
<script src="js/libs/hammer/swipeout.js"></script>
</head>
我的main.js
require.config({
paths: {
'jquery': 'libs/jquery/jquery.min',
'underscore': 'libs/lodash/lodash.min',
'backbone': 'libs/backbone/backbone.min',
'templates': '../templates',
'hammer': 'libs/hammer/hammer.min'
},
shim : {
}
});
require(['jquery'], function($) {
return {};
});
require([
// Load our app module and pass it to our definition function
'app'
], function(App){
// The "app" dependency is passed in as "App"
// Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
App.initialize();
});
非常感谢!
我使用SwipeOut,Hammer,Jquery和Backbone创建了一个示例Web应用程序。我已经将代码提交到github仓库。必须更改Swipeout以提供它的AMD版本,因此请使用此swipeout.js文件。
与其从index.html加载锤和刷卡,不如从任何javascript文件中异步加载它们。进行以下更改:
require.config({ paths: { 'jquery': 'libs/jquery/jquery.min', 'underscore': 'libs/lodash/lodash.min', 'backbone': 'libs/backbone/backbone.min', 'templates': '../templates', 'hammer': 'libs/hammer/hammer.min', 'swipeout': 'libs/hammer/swipeout' }, shim : { 'backbone': { deps: ['underscore', 'jquery'], exports: 'Backbone' }, 'underscore': { exports: '_' }, 'jquery': { exports: '$' }, 'swipeout': { exports: 'SwipeOut' } } }); require([ // Load our app module and pass it to our definition function 'app', 'hammer', 'swipeout', 'jquery' ], function(App,Hammer,Swipeout, $){ // The "app" dependency is passed in as "App" // Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function App.initialize(); });
让我知道是否可以解决问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句