Skip to content

Instantly share code, notes, and snippets.

View basecss's full-sized avatar
🎯
Focusing

basecss basecss

🎯
Focusing
  • China
  • 13:45 (UTC +08:00)
View GitHub Profile
@basecss
basecss / localStorage.js
Created January 26, 2014 12:55
localStorage
function localStorageSupport() {
try {
return ('localStorage' in window && window['localStorage'] !== null)
} catch(e) {
console.log(e.stack);
}
return false;
}
function addData(key, data) {
@basecss
basecss / localStorageSpace.js
Created January 26, 2014 11:44
check localStorageSpace
var localStorageSpace = function(){
var data = '';
for(var key in window.localStorage) {
if(window.localStorage.hasOwnProperty(key)) {
data += window.localStorage[key];
console.log(key + ' = ' + ((window.localStorage[key].length * 16) / (8 * 1024)).toFixed(2) + ' KB');
@basecss
basecss / loop.less
Created January 18, 2014 17:22
loop for less
.loop(@index) when (@index > 0) {
selector:nth-child(@index) {
property: @index * 1px; // use @index
}
.loop(@index - 1); // 递归
}
// Example
.loop(@index) when (@index > 0) {
@basecss
basecss / html_head.html
Created December 17, 2013 01:13
html head
<!DOCTYPE html> <!-- HTML5 doctype 不区分大小写 -->
<html lang="zh-cmn-Hans-CN"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa -->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 优先使用IE最新版本和 Chrome -->
<!-- width=device-width 会导致 iPhone 5 添加到主屏后以 WebAPP 全屏模式打开页面时出现黑边 http://bigc.at/ios-webapp-viewport-meta.orz -->
<meta name ="viewport" content ="initial-scale=1.0, maximum-scale=3, minimum-scale=1, user-scalable=no">
@basecss
basecss / dabblet.css
Created November 25, 2013 06:26
iOS7 style checkbox and radio
/*
* iOS7 style checkbox and radio
*/
body {
margin:30px;
}
input[type=checkbox], input[type=radio] {
appearance: none;
-webkit-appearance: none;
box-shadow: inset 0px 0px 0px 1px #e6e6e6;
@basecss
basecss / dabblet.css
Created November 22, 2013 06:01
dabblet.com 预览 gist 代码片段
body {
margin: 0;
padding: 0;
background: #09F;
}
.dialog {
position: absolute;
left: 50%;
top: 50%;
width: 500px;
@basecss
basecss / clone.js
Created November 22, 2013 01:15
Object clone
/*
* 浅复制,子类实例引用类型属性的修改会影响父类对应的属性
*/
function clone(parent, child) {
var i;
child = child || {};
for(i in parent){
if(parent.hasOwnProperty(i)){
@basecss
basecss / simple-dom.js
Created November 11, 2013 14:50
simple DOM handler
(function(win, doc){
var $ = function(selector) {
// 获取元素的方法映射
var matches = {
'#': 'getElementById',
'.': 'getElementsByClassName',
'@': 'getElementsByName',
'*': 'getElementsByTagName',
@basecss
basecss / loadScript-usage.md
Last active March 14, 2016 02:52
动态载入脚本

loadScript()方法每次只能载入一个文件,在载入多个文件的时候除了FireFox和Opera能够按照指定的顺序执行脚本。其他都懒起都无法按照指定顺序执行脚本。可以使用嵌套回调的方式解决这个问题。

loadScript('a.js', function(){
	loadScript('b.js', function(){
		loadScript('c.js', function(){
			loadScript('d.js', function(){
				// do something
			});
 });
@basecss
basecss / autofocus.html
Created November 11, 2013 02:00
autofocus for old browser
<input type="text" id="search" name="" autofocus>
<script type="text/javascript">
(function(inputField){
// typeof inputField.autofocus === 'boolean'
// or !inputField.autofocus
if(inputField.autofocus !== true){
inputField.focus();
}
})(document.getElementById('search'));