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

javascript - Is it possible to use Materializecss without jQuery? - Stack Overflow

programmeradmin2浏览0评论

I would like to use materializecss without jQuery. For example, I want to do the following without the use of jQuery:

$('.chips-initial').material_chip({
    data: [{
      tag: 'Apple',
    }, {
      tag: 'Microsoft',
    }, {
      tag: 'Google',
    }],
  });

Thanks

I would like to use materializecss without jQuery. For example, I want to do the following without the use of jQuery:

$('.chips-initial').material_chip({
    data: [{
      tag: 'Apple',
    }, {
      tag: 'Microsoft',
    }, {
      tag: 'Google',
    }],
  });

Thanks

Share Improve this question edited Feb 20, 2017 at 20:10 technophobia 2,6291 gold badge23 silver badges30 bronze badges asked Feb 20, 2017 at 19:56 rjarabarjaraba 1032 silver badges10 bronze badges 2
  • 1 materializecss.com/getting-started.html One last thing to note is that you have to import jQuery before importing materialize.js! – Gardelin Commented Feb 20, 2017 at 20:03
  • @tuna Which is a shame, since jQuery use seems to be slowing down nowadays. Every framework out there that relies on it has opened issues asking this very thing. – mkvlrn Commented Apr 21, 2017 at 19:55
Add a comment  | 

3 Answers 3

Reset to default 9

Starting with Materialize 1.0.0, jQuery is not a dependency anymore.

See https://medium.com/@materializecss/materialize-to-1-0-and-beyond-e0233b8ac15

Previous releases still rely on jQuery. Alternatively you can use Cash by Ken Wheeler.

Since version 1.0.0 you can.

const elem = document.querySelector('.chips');
const instance = M.Chips.init(elem, options);

List of possible options for the chips.

For Angular2+ you'll need:

npm install materialize-css

In package.json

"dependencies": {
    "materialize-css": "^1.0.0-alpha.4",
}

or later version.

In .angular-cli.json

  "styles": [
    "../node_modules/materialize-css/dist/css/materialize.css"
  ],
  "scripts": [
    "../node_modules/materialize-css/dist/js/materialize.js"
  ],

And to be able to use M object in your components, simply add to the imports

declare const M: any;

Yes, it is possible. Add this to the head section of each HTML document.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

Then you can add classes to tags to add styles. There are lots of useful tutorials that can be found on google search. My favorite one is right here:

https://www.youtube.com/watch?v=gCZ3y6mQpW0&list=PL4cUxeGkcC9gGrbtvASEZSlFEYBnPkmff&ab_channel=TheNetNinja

发布评论

评论列表(0)

  1. 暂无评论