简体   繁体   中英

How do I use jquery plugins with browserify?

I've installed jquery-ui via npm:

npm install jquery-ui --save

and I've come across the notion of shimming but I believe shims are no longer necessary. I think my code should just work but it doesn't. here's what I've got:

-- login.js --
require('jquery-ui');
require('jquery-ui/effect-shake');

module.exports = {
  init: function() {
    var elem = $(...); // some element on the page    
    elem.effect('shake');
  }
};

which gets browserified and included in my main page. this is how the call gets made:

-- index.html --
<head>
<script src="browserified.js"></script>
<script>
  $().ready(function() {
    login.init();
  });
</script>

so the issue I have is that .effect is not a function. am I requiring this incorrectly?

browserified.js:5571 Uncaught TypeError: elem.effect is not a function

what am I missing?

I used to bind jquery-ui effect by triggering .hide() and then .show() to the element with options. so, it would be:

module.exports = {
  init: function() {
    var elem = $(...); // some element on the page    
    elem.hide();
    elem.show({duration:300, easing:"shake"});
  }
};

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