最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: $(...).velocity is not a function - Stack Overflow

programmeradmin1浏览0评论

I have the following code:

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
    };

}();

When togglePanel() gets triggered, the following error gets thrown:

Uncaught TypeError: $(...).velocity is not a function

Which is usually solved by making sure you're loading JQuery before a library that requires it. But, I am..

var $ = require('jquery'); // first
var velocity = require('velocity-animate'); // second

So.. what gives?

I have the following code:

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
    };

}();

When togglePanel() gets triggered, the following error gets thrown:

Uncaught TypeError: $(...).velocity is not a function

Which is usually solved by making sure you're loading JQuery before a library that requires it. But, I am..

var $ = require('jquery'); // first
var velocity = require('velocity-animate'); // second

So.. what gives?

Share asked Apr 20, 2016 at 8:05 user818700user818700 1
  • I don't get why you assign jQuery to a local var and not globaly - only globaly velocity can use it. I also don't get why you assign the requirement of velocity to a local variable as well. – Seika85 Commented Apr 20, 2016 at 8:15
Add a ment  | 

1 Answer 1

Reset to default 7

From the documentation:

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 });

You've only assigned jQuery to a local $ variable.

发布评论

评论列表(0)

  1. 暂无评论