admin管理员组文章数量:1026989
First of all, I would like to highlight that I am quite a newbie in javascript programming and am trying to learn as much as I can from here. Reading the enquire js api, documentations as well as the sourcecode. I would like to know what is the difference between enquire js and the conventional using matchmedia and resize event listeners.
Link to enquire js:.js/
Would appreciate any contribution
First of all, I would like to highlight that I am quite a newbie in javascript programming and am trying to learn as much as I can from here. Reading the enquire js api, documentations as well as the sourcecode. I would like to know what is the difference between enquire js and the conventional using matchmedia and resize event listeners.
Link to enquire js:http://wicky.nillia.ms/enquire.js/
Would appreciate any contribution
Share Improve this question asked Oct 9, 2013 at 1:59 Lionel KohLionel Koh 1991 gold badge1 silver badge13 bronze badges1 Answer
Reset to default 9enquire author here :) I occasionally keep an eye on questions asked about it on SO, so I can offer help.
There is no difference as such, enquire is built on top of matchMedia. So a more pertinent question might be "what does enquire offer above and beyond the matchMedia API?"
Enquire, at it's most basic is a simple wrapper around the matchMedia API. It's goal is to eliminate the boilerplate code you constantly write with matchMedia (it's not a very nice API on it's own). It also gives more of a full lifecycle for dealing with media queries: setup (which can be optionally deferred), match, unmatch, destroy. You'd have to handle all that yourself without enquire. Also, it simplifies unregistering media queries and provides a trap door for older browsers, with shouldDegrade
In other words, enquire is good where you're doing fairly advanced stuff with MQs in JS. Otherwise, you can just use the raw matchMedia API - which I definitely remend for simple stuff. If you go down this route, definitely do not use resize events as then you have to put logic in to debounce events etc. and it gets plex quick! Instead use the browser's native MediaQueryList.addListener:
matchMedia("screen and (min-width:40em)").addListener(function(mql) {
if(mql.matches) {
// do something when matching
}
else {
// do soemthing when no match
}
});
Hope that clears things up for you
First of all, I would like to highlight that I am quite a newbie in javascript programming and am trying to learn as much as I can from here. Reading the enquire js api, documentations as well as the sourcecode. I would like to know what is the difference between enquire js and the conventional using matchmedia and resize event listeners.
Link to enquire js:.js/
Would appreciate any contribution
First of all, I would like to highlight that I am quite a newbie in javascript programming and am trying to learn as much as I can from here. Reading the enquire js api, documentations as well as the sourcecode. I would like to know what is the difference between enquire js and the conventional using matchmedia and resize event listeners.
Link to enquire js:http://wicky.nillia.ms/enquire.js/
Would appreciate any contribution
Share Improve this question asked Oct 9, 2013 at 1:59 Lionel KohLionel Koh 1991 gold badge1 silver badge13 bronze badges1 Answer
Reset to default 9enquire author here :) I occasionally keep an eye on questions asked about it on SO, so I can offer help.
There is no difference as such, enquire is built on top of matchMedia. So a more pertinent question might be "what does enquire offer above and beyond the matchMedia API?"
Enquire, at it's most basic is a simple wrapper around the matchMedia API. It's goal is to eliminate the boilerplate code you constantly write with matchMedia (it's not a very nice API on it's own). It also gives more of a full lifecycle for dealing with media queries: setup (which can be optionally deferred), match, unmatch, destroy. You'd have to handle all that yourself without enquire. Also, it simplifies unregistering media queries and provides a trap door for older browsers, with shouldDegrade
In other words, enquire is good where you're doing fairly advanced stuff with MQs in JS. Otherwise, you can just use the raw matchMedia API - which I definitely remend for simple stuff. If you go down this route, definitely do not use resize events as then you have to put logic in to debounce events etc. and it gets plex quick! Instead use the browser's native MediaQueryList.addListener:
matchMedia("screen and (min-width:40em)").addListener(function(mql) {
if(mql.matches) {
// do something when matching
}
else {
// do soemthing when no match
}
});
Hope that clears things up for you
本文标签: javascriptDifference between matchmedia and enquire jsStack Overflow
版权声明:本文标题:javascript - Difference between matchmedia and enquire js - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745669324a2162364.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论