Uncaught TypeError: $(...).velocity is not a function
Uncaught TypeError: $(...).velocity is not a function
我有以下代码:
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()
被触发时,抛出以下错误:
Uncaught TypeError: $(...).velocity is not a function
这通常可以通过确保在需要它的库之前加载 JQuery 来解决。但是,我是..
var $ = require('jquery'); // first
var velocity = require('velocity-animate'); // second
那么..是什么给了?
Module Loader: Browserify
If you're using Velocity with jQuery, you must require jQuery before Velocity, and you must assign
jQuery globally on the window object:
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 分配给 local $
变量。
我有以下代码:
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()
被触发时,抛出以下错误:
Uncaught TypeError: $(...).velocity is not a function
这通常可以通过确保在需要它的库之前加载 JQuery 来解决。但是,我是..
var $ = require('jquery'); // first
var velocity = require('velocity-animate'); // second
那么..是什么给了?
Module Loader: Browserify
If you're using Velocity with jQuery, you must require jQuery before Velocity, and you must assign jQuery globally on the window object: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 分配给 local $
变量。