skel doc

Skel

Skel is a lightweight framework for building responsive sites and web apps. Features include:
skel是一個(gè)輕量級(jí)的構(gòu)建響應(yīng)式頁(yè)面的框架垛吗,特點(diǎn)包括:

  • Access to CSS breakpoints via JS (enabling stuff like if (skel.breakpoint("small").active) { /* do something specific for small displays */ }).
    通過js訪問css斷點(diǎn),例如: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).
    事件,包括經(jīng)常使用的“l(fā)oad”,“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歇父,無(wú)論在head標(biāo)簽中還是body標(biāo)簽中都不要緊,

<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()方法來明確你的斷點(diǎn)再愈,(可以由 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:
差不多就是這個(gè)樣子了榜苫,你可以想下面這樣做一些事情了:

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

        /* do DOM ready stuff
            做DOM準(zhǔn)備工作
         */

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

        if (skel.vars.touch) {
            /* enable feature for devices with a touchscreen
                為觸摸設(shè)備寫一些特征
             */
        }

        if (skel.vars.IEVersion < 9) {
            /* apply workaround for IE<9
                針對(duì)IE9寫的一些方法
             */
        }

    })
    .on("+large", function() {
        /* do something when "large" breakpoint becomes active
        當(dāng)large斷點(diǎn)變活躍時(shí)要做的事
         */
    })
    .on("-large !large", function() {
        /* do something when "large" breakpoint is (or becomes) inactive 
        做一些事情當(dāng)large斷點(diǎn)為活躍或者要抵達(dá)這個(gè)斷點(diǎn)的時(shí)候*/
    });

Breakpoints-斷點(diǎn)是什么?

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的斷點(diǎn)翎冲,通過簡(jiǎn)單的調(diào)用skel.breakpoints()垂睬,傳遞一個(gè)媒體查詢列表來設(shè)置斷點(diǎn),格式如下

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:
在這些地方抗悍, 私有的斷點(diǎn)對(duì)象可以檢索到斷點(diǎn)驹饺,使用skel.breakpoint(),例如:

// Get the "small" breakpoint object. 獲取small這個(gè)斷點(diǎn)的對(duì)象
var x = skel.breakpoint("small");

Breakpoint objects have the following properties:
斷點(diǎn)對(duì)象有下面這些屬性,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.

    布爾型對(duì)象衔沼,如果當(dāng)前斷點(diǎn)是活躍的蝌借,那么設(shè)置為true,當(dāng)前的時(shí)候狀態(tài)滿足媒體查詢的規(guī)定指蚁,如果不是菩佑,那么是false;

  • wasActive

    (bool) Set to true if the breakpoint was active before the last state change, or false if not.
    布爾型凝化,如果目標(biāo)斷點(diǎn)在最后的狀態(tài)改變之前是wasactive的狀態(tài)稍坯,那就是true,反之是false缘圈;

  • name

    (string) The breakpoint's name.
    字符串,這個(gè)是斷點(diǎn)的名字袜蚕。

  • media

    (string) The breakpoint's media query.
    字符串糟把,斷點(diǎn)是媒體查詢

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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市牲剃,隨后出現(xiàn)的幾起案子遣疯,更是在濱河造成了極大的恐慌,老刑警劉巖凿傅,帶你破解...
    沈念sama閱讀 212,454評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缠犀,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡聪舒,警方通過查閱死者的電腦和手機(jī)辨液,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來箱残,“玉大人滔迈,你說我怎么就攤上這事止吁。” “怎么了燎悍?”我有些...
    開封第一講書人閱讀 157,921評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵敬惦,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我谈山,道長(zhǎng)俄删,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,648評(píng)論 1 284
  • 正文 為了忘掉前任奏路,我火速辦了婚禮畴椰,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘思劳。我一直安慰自己迅矛,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評(píng)論 6 386
  • 文/花漫 我一把揭開白布潜叛。 她就那樣靜靜地躺著秽褒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪威兜。 梳的紋絲不亂的頭發(fā)上销斟,一...
    開封第一講書人閱讀 49,950評(píng)論 1 291
  • 那天,我揣著相機(jī)與錄音椒舵,去河邊找鬼蚂踊。 笑死,一個(gè)胖子當(dāng)著我的面吹牛笔宿,可吹牛的內(nèi)容都是我干的犁钟。 我是一名探鬼主播,決...
    沈念sama閱讀 39,090評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼泼橘,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼涝动!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起炬灭,我...
    開封第一講書人閱讀 37,817評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤醋粟,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后重归,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體米愿,經(jīng)...
    沈念sama閱讀 44,275評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評(píng)論 2 327
  • 正文 我和宋清朗相戀三年鼻吮,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了育苟。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,724評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡椎木,死狀恐怖宙搬,靈堂內(nèi)的尸體忽然破棺而出笨腥,到底是詐尸還是另有隱情,我是刑警寧澤勇垛,帶...
    沈念sama閱讀 34,409評(píng)論 4 333
  • 正文 年R本政府宣布脖母,位于F島的核電站,受9級(jí)特大地震影響闲孤,放射性物質(zhì)發(fā)生泄漏谆级。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評(píng)論 3 316
  • 文/蒙蒙 一讼积、第九天 我趴在偏房一處隱蔽的房頂上張望肥照。 院中可真熱鬧,春花似錦勤众、人聲如沸舆绎。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)吕朵。三九已至,卻和暖如春窥突,著一層夾襖步出監(jiān)牢的瞬間努溃,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工阻问, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留梧税,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,503評(píng)論 2 361
  • 正文 我出身青樓称近,卻偏偏與公主長(zhǎng)得像第队,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子刨秆,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容