简体   繁体   中英

Using the npm version of a jQuery plugin?

I have been working with the excellent noUISlider jQuery plugin and now I want to start using the npm version as I am moving my JS to use node and browserify.

However I don't understand how to adapt my code to work with the npm version, and I don't understand why there is no documentation about this. Am I missing something basic about how node works?

I have run npm install --save nouislider-browser . Now here's my JS:

    var slider = require('nouislider-browser');

    $("#slider-date").noUiSlider({
        start: [20, 80],
        connect: true,
        range: {
            'min': 0,
            'max': 100
        }
    });

This does not error on the var slider line, but it errors on the $("#slider-date").noUiSlider({... line, saying Uncaught TypeError: $(...).noUiSlider is not a function .

I guess there's some way to set up the slider using the slider object, but how? There isn't anything in the npm package documentation about this.

The index.js file in the NPM is empty except for this comment:

// placeholder, so require.resolve('xxx-browser') gives root path.

So I think you'll need to do this instead:

require('nouislider-browser/jquery.nouislider');

BTW I don't think you need the var slider = .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM