在 Browserify 中使用 Velocity.js 时如何访问 $.velocity.RunSequence?
How can I access $.velocity.RunSequence when using Velocity.js with Browserify?
我的代码:
var Backbone = require('backbone');
var $ = require('jquery');
Backbone.$ = $;
var velocity = require('velocity-animate');
module.exports = function (obj) {
var obj = obj || {};
return Backbone.View.extend({
tagName: 'article',
className: 'lab-notes__article--single',
initialize: function () {
var _this = this;
_this.collection.deferred.done(function () {
var _thePost = _this.collection.first();
_this.model = _this.collection.find(function(model) {
return model.get('slug') === data.slug;
});
_this.render();
});
},
render: function () {
var _this = this;
var data = this.model.attributes;
var JST = require('../templates/blog-post-single.html')(data);
this.$el.html(JST);
$('[data-blog-post-single]').html(this.el);
var openBlogPost = [
{ e: $('body'), p: 'scroll', o: { duration: 100, duration: 500, easing: 'easeInOutQuart', } },
{ e: _this.$el, p: 'fadeIn', o: { duration: 200 } }
];
$.velocity.RunSequence(openBlogPost);
}
});
};
… 运行 我收到的错误是:
Uncaught TypeError: Cannot read property 'RunSequence' of undefined
出现在这一行:
$.velocity.RunSequence(openBlogPost);
我不确定发生了什么,但我感觉这与我对 Velocity 的需求有关。有什么建议吗?
文档包含有关使用 browserify 的部分:
window.jQuery = window.$ = require("path/to/jquery-x.x.x.js");
require("path/to/velocity.js");
// Optional: If you're using the UI pack, require it after Velocity. (You don't need to assign it to a variable.)
require("path/to/velocity.ui.js");
与其创建名为 $
的局部变量,不如尝试在全局 (a.k.a window
) 范围内创建它以及 jQuery
命名空间。另外,确保 velocity-animate
指向正确的文件(我记得它是 npm 上的包的名称,而不一定是你项目中 Velocity 的路径)。
为了让它工作,我必须从这里更改要求行:
var velocity = require('velocity-animate');
… 对此:
velocity = $.velocity = require('velocity-animate');
我的代码:
var Backbone = require('backbone');
var $ = require('jquery');
Backbone.$ = $;
var velocity = require('velocity-animate');
module.exports = function (obj) {
var obj = obj || {};
return Backbone.View.extend({
tagName: 'article',
className: 'lab-notes__article--single',
initialize: function () {
var _this = this;
_this.collection.deferred.done(function () {
var _thePost = _this.collection.first();
_this.model = _this.collection.find(function(model) {
return model.get('slug') === data.slug;
});
_this.render();
});
},
render: function () {
var _this = this;
var data = this.model.attributes;
var JST = require('../templates/blog-post-single.html')(data);
this.$el.html(JST);
$('[data-blog-post-single]').html(this.el);
var openBlogPost = [
{ e: $('body'), p: 'scroll', o: { duration: 100, duration: 500, easing: 'easeInOutQuart', } },
{ e: _this.$el, p: 'fadeIn', o: { duration: 200 } }
];
$.velocity.RunSequence(openBlogPost);
}
});
};
… 运行 我收到的错误是:
Uncaught TypeError: Cannot read property 'RunSequence' of undefined
出现在这一行:
$.velocity.RunSequence(openBlogPost);
我不确定发生了什么,但我感觉这与我对 Velocity 的需求有关。有什么建议吗?
文档包含有关使用 browserify 的部分:
window.jQuery = window.$ = require("path/to/jquery-x.x.x.js");
require("path/to/velocity.js");
// Optional: If you're using the UI pack, require it after Velocity. (You don't need to assign it to a variable.)
require("path/to/velocity.ui.js");
与其创建名为 $
的局部变量,不如尝试在全局 (a.k.a window
) 范围内创建它以及 jQuery
命名空间。另外,确保 velocity-animate
指向正确的文件(我记得它是 npm 上的包的名称,而不一定是你项目中 Velocity 的路径)。
为了让它工作,我必须从这里更改要求行:
var velocity = require('velocity-animate');
… 对此:
velocity = $.velocity = require('velocity-animate');