Skip to content

Instantly share code, notes, and snippets.

/*
* UnitBezier
* from: https://chromium.googlesource.com/chromium/blink/+/master/Source/platform/animation/UnitBezier.h
* version: 0.0.1
*/
"use strict";
;(function (global, factory) {
if ("function" === typeof define && define.amd) {
define(function () {
;(function (global, factory) {
"use strict";
var moduleName = "FastClick";
if (typeof define === "function" && define.amd) {
define(function () {
return (global[moduleName] = factory(global));
});
} else if (typeof module === "object" && module.exports) {
@zbinlin
zbinlin / dom.js
Last active August 29, 2015 14:10
遍历 DOM 节点
/* 深度优先 */
function dom1(el, isBack) {
isBack || ++idx;
if (!el) {
return;
}
var next = isBack ? el.nextElementSibling : (el.firstElementChild || el.nextElementSibling);
return dom1(next ? next : el.parentNode, !next);
}
@zbinlin
zbinlin / toChineseNumerals.js
Created December 2, 2014 13:54
数字转大写
function toChineseNumerals(num) {
if (!/^(\d+)(?:\.(\d{1,2}))?$/.test(num)) return "";
var m = RegExp["$1"], n = RegExp["$2"];
var a = ["", "萬", "億", "兆", "京", "垓", "秭", "穰", "沟", "涧", "正", "载"];
var b = ["", "十", "百", "千"];
var c = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
var d = ["角", "分"];
return "(大写)" + m.split("").reverse().join("").match(/.{1,4}/g).map(function (item, index, array) {
return b.reduceRight(function (prev, cur, idx, arr) {
return prev += c[item[idx] >>> 0] + cur;
var Uint32 = {
"~": function (a) {
return ~a >>> 0;
},
not: function (a) {
return this["~"](a);
},
"&": function (a, b) {
return (a & b) >>> 0;
Math.mod = function (a, b) {
return (a - Math.floor(a / b) * b);
};
Math.rem = function (a, b) {
return (a - ((a / b) | 0) * b);
};
Math.sign = function (a) {
return 0 > a ? -1 : 1;
};