Javascript 未捕获类型错误:$(…)。速度不是函数
我有以下代码:Javascript 未捕获类型错误:$(…)。速度不是函数,javascript,jquery,browserify,velocity,commonjs,Javascript,Jquery,Browserify,Velocity,Commonjs,我有以下代码: var $ = require('jquery'); var velocity = require('velocity-animate'); module.exports = function () { function togglePanel () { $('.trip-assist-search-panel__container').velocity({ height: '0px' },{
var $ = require('jquery');
var velocity = require('velocity-animate');
module.exports = function () {
function togglePanel () {
$('.trip-assist-search-panel__container').velocity({
height: '0px'
},{
duration: 400
});
}
return {
togglePanel: togglePanel
};
}();
触发togglePanel()
时,会引发以下错误:
未捕获类型错误:$(…)。速度不是函数
这通常通过确保在需要JQuery的库之前加载JQuery来解决。但是,我是
var $ = require('jquery'); // first
var velocity = require('velocity-animate'); // second
所以。。提供了什么?来自:
模块加载器:Browserify如果将Velocity与jQuery一起使用,则必须在Velocity之前使用jQuery,并且必须指定 在窗口对象上全局执行jQuery:
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");
/* Your app code here. */
$("body").velocity({ opacity: 0.5 });
您只将jQuery分配给了一个本地
$
变量。我不明白为什么您将jQuery分配给本地变量而不是全局变量-只有全局velocity可以使用它。我也不明白为什么要把速度的要求也指定给一个局部变量。