Giter Club home page Giter Club logo

tingle-context's Introduction

Context

tingle的上下文模块,提供全局性的属性和方法。

手势事件去差异

  • TOUCH_START:移动端的值是touchstart,PC端的值是mousedown
  • TOUCH_MOVE:移动端的值是touchmove,PC端的值是mousemove
  • TOUCH_END:移动端的值是touchend,PC端的值是mouseup
  • TOUCH_CANCEL:移动端的值是touchcancel,PC端的值是mouseup

是什么环境

  • isMobile:boolean,是否是运行在移动端,目前没有区分padpad环境下该值为true
  • isPC:boolean,是否是运行在PC端

是否支持

  • support3D:是否支持css硬件加速
  • supportHairline:是否支持0.5px的细线
  • supportTouch:是否支持移动端手势

getTID

获取自增长的id

Context.getTID(); // 0
Context.getTID(); // 1

mixin

合并对象,功能同jQueryextend

var obj = Context.mixin({name:'tingle'}, {age:'1'});
// obj === {'name':'tingle', 'age':'1'}

noop

空函数,常用于回调函数的默认函数

TextField.defaultProps = {
    onChange: Context.noop
}

rem(px, artBoardWidth)

px单位的值转换为rem单位的值。

参数:

  • px:{Number},必选项。表示要被转换的值。
  • artBoardWidth:{Number},可选。计算rem时要基于的画板宽度,即设计稿的实际宽度,默认750px

使用:

Context.rem(750); // 基于`750px`的设计稿,`750px`等于`10rem`
Context.rem(750, 640); // 基于`640px`的设计稿,`750px`等于`11.71875rem`

makePrivateRem(artBoardWidth)

以指定画板宽度(artBoardWidth)创建私有的rem方法。

参数:

  • artBoardWidth:{Number},可选。计算rem时要基于的画板尺寸,即设计稿的实际尺寸。

使用:

var Context = require('tingle-context');
var privateRem = Context.makePrivateRem(640); // 创建基于`640px`宽的`rem`方法
privateRem(750); // 基于`640px`的设计稿,`750px`等于`11.71875rem`

// 默认的`rem`方法是基于`750px`宽的设计稿
Context.rem(750); // 10rem

TODOs

  • 添加set方法,用于全局配置tingle的运行环境。如Tingle.set('artBoardWidth', 640)

updates

v0.1.0 (2015-08-25)

  • ES6化。
  • 简化环境判断的层级,如:Context.is.pc改为Context.isPC

v0.0.4 (2015-08-18)

  • 0.5px支持,在html元素的class中以hairline标识。
  • 无入侵的rem方案支持,添加rem方法和makePrivateRem方法。

v0.0.3 (2015-07-14)

  • 添加文档

tingle-context's People

Contributors

gbk avatar liuminjie avatar yize avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.