enquire.js - JavaScript 媒体查询库


MIT
跨平台
JavaScript

软件简介

enquire.js 是轻量级,纯 JavaScript 实现的 CSS 媒体查询库:

  • JavaScript 回调媒体查询,匹配或者不匹配

  • 干净直观的 API

  • 超轻量级 —— 大约 0.8kb minified & gzipped!

完全无依赖,甚至是 jQuery。

简单使用:

enquire.register("screen and (max-width:45em)", {
    // OPTIONAL
    // If supplied, triggered when a media query matches.
    match : function() {},      
                                
    // OPTIONAL
    // If supplied, triggered when the media query transitions 
    // *from a matched state to an unmatched state*.
    unmatch : function() {},    
    
    // OPTIONAL
    // If supplied, triggered once, when the handler is registered.
    setup : function() {},    
                                
    // OPTIONAL, defaults to false
    // If set to true, defers execution of the setup function 
    // until the first time the media query is matched
    deferSetup : true,
                                
    // OPTIONAL
    // If supplied, triggered when handler is unregistered. 
    // Place cleanup code here
    destroy : function() {}
      
});