skel doc

作者: 雨和眼泪 | 来源:发表于2018-01-23 16:50 被阅读0次

Skel

Skel is a lightweight framework for building responsive sites and web apps. Features include:
skel是一个轻量级的构建响应式页面的框架,特点包括:

  • Access to CSS breakpoints via JS (enabling stuff like if (skel.breakpoint("small").active) { /* do something specific for small displays */ }).
    通过js访问css断点,例如:if (skel.breakpoint("small").active) { /* do something specific for small displays */ }.表示在小型的屏幕上要做的事情

  • Events, including the commonly used (load, ready) and special ones just for breakpoints (+breakpoint, -breakpoint).
    事件,包括经常使用的“load”,“ready”,还有特殊的事件:“+breakpoint”,"-breakpoint"

  • Vars, for convenient access to information about the client's browser, operating system, and more.
    变量,为了方便访问、连接客户的浏览器的信息等

  • Extendable with modules (like Layout and Viewport).
    可拓展的模块,例如layout和viewport

Usage-使用方法

Load skel.min.js (either in your <head> tag or before </body> -- doesn't matter) to create the global skel object:
加载skel.min.js,无论在head标签中还是body标签中都不要紧,

<script src="skel.min.js"></script>

Then use skel.breakpoints() to define your breakpoints (each consisting of a name and a media query):
然后使用skel.breakpoints()方法来明确你的断点,(可以由 name 或者以媒体查询组成)

skel.breakpoints({
    xlarge: "(max-width: 1680px)",
    large:  "(max-width: 1280px)",
    medium: "(max-width: 980px)",
    small:  "(max-width: 736px)",
    xsmall: "(max-width: 480px)"
});

That's pretty much it. You can now do stuff like:
差不多就是这个样子了,你可以想下面这样做一些事情了:

skel
    .on("ready", function() {

        /* do DOM ready stuff
            做DOM准备工作
         */

        if (skel.breakpoint("small").active) {
            /* do something specific for small displays
                做一些为小型显示器特定的一些工作
             */
        }

        if (skel.vars.touch) {
            /* enable feature for devices with a touchscreen
                为触摸设备写一些特征
             */
        }

        if (skel.vars.IEVersion < 9) {
            /* apply workaround for IE<9
                针对IE9写的一些方法
             */
        }

    })
    .on("+large", function() {
        /* do something when "large" breakpoint becomes active
        当large断点变活跃时要做的事
         */
    })
    .on("-large !large", function() {
        /* do something when "large" breakpoint is (or becomes) inactive 
        做一些事情当large断点为活跃或者要抵达这个断点的时候*/
    });

Breakpoints-断点是什么?

Skel's primary feature is its ability to make CSS breakpoints accessible via JS. To set this up, simply call skel.breakpoints() with a list of media queries (presumably mirroring those found in your CSS) in the following format:
skel主要的特称是通过js来控制css的断点,通过简单的调用skel.breakpoints(),传递一个媒体查询列表来设置断点,格式如下

skel.breakpoints({
    name: "media query",
    name: "media query",
    name: "media query",
    ...
});

Where name is a unique identifier for each breakpoint (eg. medium). For example, the following defines 5 breakpoints (xlarge, large, medium, small, and xsmall):

skel.breakpoints({
    xlarge: "(max-width: 1680px)",
    large:  "(max-width: 1280px)",
    medium: "(max-width: 980px)",
    small:  "(max-width: 736px)",
    xsmall: "(max-width: 480px)"
});

With these in place, individual breakpoint objects can be retrieved using skel.breakpoint(), for example:
在这些地方, 私有的断点对象可以检索到断点,使用skel.breakpoint(),例如:

// Get the "small" breakpoint object. 获取small这个断点的对象
var x = skel.breakpoint("small");

Breakpoint objects have the following properties:
断点对象有下面这些属性,active、wasActive、name、media

  • active

    (bool) Set to true if the breakpoint is currently active (ie. the current state of the viewport satisfies its media query), or false if not.

    布尔型对象,如果当前断点是活跃的,那么设置为true,当前的时候状态满足媒体查询的规定,如果不是,那么是false;

  • wasActive

    (bool) Set to true if the breakpoint was active before the last state change, or false if not.
    布尔型,如果目标断点在最后的状态改变之前是wasactive的状态,那就是true,反之是false;

  • name

    (string) The breakpoint's name.
    字符串,这个是断点的名字。

  • media

    (string) The breakpoint's media query.
    字符串,断点是媒体查询

Events-- 事件

Skel provides a small set of common and breakpoint-oriented events. Handlers can be bound to these events using skel.on(), like so:

skel.on("event", function() {
    /* do stuff */
});

You can also bind a single handler to multiple events by providing them in a space-delimited list:

skel.on("event1 event2 ...", function() {
    /* do stuff */
});

The following events are currently supported:

  • change

    Triggered when one or more breakpoints become active or inactive.

    skel.on("change", function() {
        alert("Breakpoints changed!");
    });
    
  • init

    Triggered when Skel initializes.

    skel.on("init", function() {
        alert("Initialized!");
    });
    
  • ready

    Triggered when the DOM is ready.

    skel.on("ready", function() {
        alert("DOM is ready!");
    });
    
  • load

    Triggered when the page loads.

    skel.on("load", function() {
        alert("Page has finished loading!");
    });
    
  • +breakpointName

    Triggered when breakpointName becomes active. For example:

    skel.on("+small", function() {
        /* Turn on feature for small displays */
    });
    
  • -breakpointName

    Triggered when breakpointName becomes inactive. For example:

    skel.on("-small", function() {
        /* Turn off feature for small displays */
    });
    
  • !breakpointName

    Triggered if breakpointName is not active at the exact moment you call skel.breakpoints(). For example:

    skel.on("!small", function() {
        /* Turn on feature for non-small displays */
    });
    

Vars

Skel exposes basic information about the client (such as its browser and operating system) through the skel.vars property. For example:

alert("Your browser is " + skel.vars.browser);

This information can, among other things, be used to apply browser (and even operating system) specific workarounds for those rare but frustratingly annoying moments where feature detection fails. The following vars are currently available:

  • browser

    (string) Client's browser, which can be any of the following:

    Browser Value of browser
    Firefox firefox
    Chrome chrome
    Safari safari
    Opera opera
    Internet Explorer ie
    Edge edge
    BlackBerry bb
    Other other
  • browserVersion

    (float) Client's browser version.

  • IEVersion

    (float) If the client is using any version of IE, this will be set to its version number (eg. 8 for IE8, 11 for IE11). However, if they're using anything other than IE, this will be set to 99, effectively reducing legacy IE checks to a single condition. For example:

    if (skel.vars.IEVersion < 9) {
        /* This will only execute if the client's using IE AND its version is <9 */
    }
    
  • os

    (string) Client's operating system, which can be any of the following:

    Operating System Value of os
    Android android
    iOS ios
    Windows Phone wp
    Mac OS X mac
    Windows windows
    BlackBerry bb
    Other other
  • osVersion

    (float) Client's operating system version.

  • touch

    (bool) Set to true if the client is using a device with a touchscreen, or false if not.

    Note: A value of true does not imply the abscence of a mouse and keyboard.

  • mobile

    (bool) Set to true if the client is using what's considered a "mobile OS" (currently iOS, Android, Windows Phone, and BlackBerry), or false if not. Equivalent to:

    (skel.vars.os == "wp" || skel.vars.os == "android" || skel.vars.os == "ios" || skel.vars.os == "bb")
    
  • stateId

    (string) Current state ID. A state, in Skel terms, is a specific combination of active breakpoints, and a state ID is the unique identifier used to reference that state internally. For example, given the breakpoints medium, small, and xsmall (defined in that exact order):

    Active Breakpoints Value of stateId
    medium /medium
    small /small
    small and xsmall /small/xsmall
    (none) /

    While stateId is primarily meant for Skel's own internal use, it can come in handy elsewhere (eg. to perform an action when a very specific combination of breakpoints is active).

  • lastStateId

    (string) The value of stateId before the last state change, or null if the state hasn't changed yet.

Credits

License

Skel is released under the MIT license.

Copyright (c) skel.io

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

相关文章

网友评论

      本文标题:skel doc

      本文链接:https://www.haomeiwen.com/subject/gjaowxtx.html