Skip to content

Instantly share code, notes, and snippets.

View fwon's full-sized avatar
🎯
Focusing

Feng Wang fwon

🎯
Focusing
View GitHub Profile
@fwon
fwon / casper.test.js
Created September 15, 2014 05:43
casper filling and login test
casper.test.begin('test 163 mail login', 2, function(test) {
casper.start('http://mail.163.com/', function() {
this.capture('step1.png');
test.assertExists('#loginBtn');
this.fill('form', {
'username': 'xxx',
'password': 'xxx'
}, true);
this.click('#loginBtn');
this.capture('step2.png');
@fwon
fwon / factory.js
Created October 21, 2014 15:10
工厂模式
//工厂模式
function Factory () {}
Factory.prototype.defaultGender = Boy;
Factory.prototype.createFactory = function (options) {
if (options.name === 'girl') {
this.defaultGender = Girl;
} else {
this.defaultGender = Boy;
}
return new this.defaultGender(options);
@fwon
fwon / text.css
Created November 4, 2014 03:54
text css3
display -webkit-box
-webkit-line-clamp 1
text-overflow ellipsis
-webkit-box-orient vertical
word-break break-all
@fwon
fwon / design_pattern.txt
Created November 4, 2014 14:17
设计模式
//设计模式
Singleton(单例)模式
限制了类的实例化次数只能为一次
getInstance = function () {
if (this._instance == null) {
this._instance = new Singletance();
}
return this._instance;
}
@fwon
fwon / basket.js
Created June 10, 2015 11:35
basket.js 笔记
//每次set的时候,检查localStorage是否溢出,做LRU处理
var addLocalStorage = function( key, storeObj ) {
try {
localStorage.setItem( storagePrefix + key, JSON.stringify( storeObj ) );
return true;
} catch( e ) {
if ( e.name.toUpperCase().indexOf('QUOTA') >= 0 ) {
var item;
var tempScripts = [];
/* bling.js */
window.$ = document.querySelectorAll.bind(document)
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn)
}
NodeList.prototype.__proto__ = Array.prototype
var n = 2;
var arr = [1,2,3,4,5,6];
var arr1 = arr.slice(0,n);
var arr2 = arr.slice(n,6)
arr1 = arr1.reverse();
arr2 = arr2.reverse();
var arr3 = arr1.concat(arr2).reverse();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style type="text/css">
#main{
position: relative;
overflow: hidden;
}
/**
* Provides requestAnimationFrame in a cross browser way.
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
*/
if ( !window.requestAnimationFrame ) {
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
/**
* @author alteredq / http://alteredqualia.com/
*/
Detector = {
// supported features
canvas : !!window.CanvasRenderingContext2D,
webgl : !!window.WebGLRenderingContext,