@0saw/foundation-media-query 中文文档教程

发布于 6年前 浏览 29 项目主页 更新于 3年前

Foundation Media Query

帮助您处理基础站点媒体查询的小巧实用工具。

没有依赖性。 除了粉底 (Da-a-ah)。 添加 CustomEvent polyfill。

Usage

import mq from "@0saw/foundation-media-query";

document.addEventListener('breakpoint-change', breakpointEventListener);

function breakpointEventListener() {
    if (mq.is('large only')) {
        console.log("You've hit the right spot");
    }
}

您没有义务将 mq 导入您的范围。 相反,您可以像这样使用 event.detail

import "@0saw/foundation-media-query";

document.addEventListener('breakpoint-change', breakpointEventListener);

function breakpointEventListener(event) {
    let mq = event.detail;

    switch (mq.current) {
        case 'medium':
            alert("You've hit the right spot");
            break;
        case 'large':
            alert("Too far");
            break;
        default:
            break;
    }
}

API

mq 对象包含一些有用的东西。

Getters

  • mq.current - Gives you the name of current breakpoint
  • mq.currentFull - Gives you all of the breakpoint info that we have. (I.e mq.currentFull.matchMedia will give you matchMedia object. In case you want to do something naughty)
  • mq.landscape - Analog of CSS's (orientation: landscape)
  • mq.portrait - Pretty straight forward
  • mq.retina - DPI is at least 2x

Methods

  • mq.is - Allows you to quickly check current breakpoint
// Either true or false
mq.is('xlarge');

// Won't return true when next breakpoint is active. ([small -> medium] -> large)
mq.is('medium only');

// portrait/ladscape/retina
mq.is('portrait');

FAQ

Foundation Media Query

Small little nifty utility to help you work with foundation-sites media queries.

No dependencies. Except for foundation (Da-a-ah). Adds CustomEvent polyfill.

Usage

import mq from "@0saw/foundation-media-query";

document.addEventListener('breakpoint-change', breakpointEventListener);

function breakpointEventListener() {
    if (mq.is('large only')) {
        console.log("You've hit the right spot");
    }
}

You are not obligated to import mq to your scope. Instead you can use event.detail like so:

import "@0saw/foundation-media-query";

document.addEventListener('breakpoint-change', breakpointEventListener);

function breakpointEventListener(event) {
    let mq = event.detail;

    switch (mq.current) {
        case 'medium':
            alert("You've hit the right spot");
            break;
        case 'large':
            alert("Too far");
            break;
        default:
            break;
    }
}

API

mq object contains a few useful things.

Getters

  • mq.current - Gives you the name of current breakpoint
  • mq.currentFull - Gives you all of the breakpoint info that we have. (I.e mq.currentFull.matchMedia will give you matchMedia object. In case you want to do something naughty)
  • mq.landscape - Analog of CSS's (orientation: landscape)
  • mq.portrait - Pretty straight forward
  • mq.retina - DPI is at least 2x

Methods

  • mq.is - Allows you to quickly check current breakpoint
// Either true or false
mq.is('xlarge');

// Won't return true when next breakpoint is active. ([small -> medium] -> large)
mq.is('medium only');

// portrait/ladscape/retina
mq.is('portrait');

FAQ

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文