Skip to content

Instantly share code, notes, and snippets.

View yuezk's full-sized avatar
💭
I may be slow to respond.

Kevin Yue yuezk

💭
I may be slow to respond.
View GitHub Profile
@yuezk
yuezk / get-global.js
Created October 23, 2013 06:50
在use strict模式下得到全局变量(node和浏览器环境通用)
//get the global var in both browser and node etc.
//reference: http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript
var Fn = Function, global = Fn('return this')();
@yuezk
yuezk / get-random.js
Created October 23, 2013 06:53
得到指定数字之间的随机数,来自《JavaScript高级程序设计》
function selectFrom(lowerValue, upperValue) {
var choices = upperValue - lowerValue + 1;
return Math.floor(Math.random() * choices + lowerValue);
}
@yuezk
yuezk / index.html
Created November 15, 2013 06:16
A Pen by Zongkun Yue.
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>文字在定高容器中垂直居中</title>
</head>
<body>
<div class="main">
<span class="valign-text">我应该是垂直居中的我应该是垂直居中的我应该是垂直居中的我应该是垂直居中的我应该是垂直居中的我应该是垂直居中的</span><i class="valign-helper"></i>
</div>
</body>
@yuezk
yuezk / mobilecheck
Created November 15, 2013 09:31
检测手机端
// http://stackoverflow.com/a/11381730/989439
function mobilecheck() {
var check = false;
(function(a){if(/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro
@yuezk
yuezk / reset.css
Created November 18, 2013 02:08
kissy css reset
/*
Copyright 2010, KISSY UI Library v1.0.8
MIT Licensed
build: 871 Jul 19 08:51
*/
/*
KISSY CSS Reset
理念:1. reset 的目的不是清除浏览器的默认样式,这仅是部分工作。清除和重置是紧密不可分的。
2. reset 的目的不是让默认样式在所有浏览器下一致,而是减少默认样式有可能带来的问题。
3. reset 期望提供一套普适通用的基础样式。但没有银弹,推荐根据具体需求,裁剪和修改后再使用。
@yuezk
yuezk / font-face.css
Last active December 28, 2015 15:39
font-face的最佳实践
/*http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax*/
@font-face {
font-family: 'Web Font';
src: url('AlexBrush-Regular.eot?#iefix') format('embedded-opentype'), /*IE*/
url('AlexBrush-Regular.woff') format('woff'), /*Chrome, Firefox, Opera, Safari*/
url('AlexBrush-Regular.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
url('AlexBrush-Regular.svg#svgFontName') format('svg'); /*iOS 4.1-*/
}
@yuezk
yuezk / padding
Last active August 29, 2015 14:07
在指定的数字前补0
/**
* @description 在指定的数字前补0
*
* @num 要补0的数字
* @length 补0之后的总长度
*
* @return 补0之后的结果
*/
function padding(num, length) {
@yuezk
yuezk / getOffset
Last active August 29, 2015 14:09
得到元素相对于document的offset
/**
* 得到元素相对于document的offset
* @param {Element} ele
* @return {object}
*/
function getOffset(ele) {
var box = {top: 0, left: 0};
var doc = ele.ownerDocument;
var docElem = doc.documentElement;
var win = doc.defaultView;
@yuezk
yuezk / A-Circular-Date-Picker.markdown
Last active August 29, 2015 14:11
A Circular Date Picker
@yuezk
yuezk / random-color.js
Created August 24, 2015 05:36
random color
// reference: http://llllll.li/randomColor/
function randomColor() {
return '#' + Math.floor(Math.random()*16777215).toString(16);
}