This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testGeolocation() { | |
return "geolocation" in navigator; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testWebgl() { | |
return !!window.WebGLRenderingContext; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testCanvas() { | |
var elem = document.createElement("canvas"); | |
return !!(elem.getContext && elem.getContext("2d")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var lastTime = 0; | |
var vendors = ['webkit', 'moz']; | |
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; | |
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // Webkit中此取消方法的名字变了 | |
window[vendors[x] + 'CancelRequestAnimationFrame']; | |
} | |
if (!window.requestAnimationFrame) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tween.js | |
* t: current time(当前时间); | |
* b: beginning value(初始值); | |
* c: change in value(变化量); | |
* d: duration(持续时间)。 | |
* you can visit 'http://easings.net/zh-cn' to get effect | |
*/ | |
var Tween = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<style> | |
#box { | |
border: 2px gray dotted; | |
width: 180px; | |
height: 160px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 需配合 load.js 使用 */ | |
var preload; | |
if (/*@cc_on!@*/false) { | |
preload = function(src) { | |
new Image().src = src; | |
}; | |
} else { | |
preload = function(src) { | |
var obj = document.createElement("object"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.method = function(name, implementation) { | |
this.prototype[name] = implementation; | |
return this; | |
}; | |
var Person = function(name) { | |
this.name = name; | |
}.method("getname", function() { | |
alert(this.name) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://javascript.crockford.com/memory/leak.html */ | |
function purge(d) { | |
var a = d.attributes, i, l, n; | |
if (a) { | |
for (i = a.length - 1; i >= 0; i -= 1) { | |
n = a[i].name; | |
if (typeof d[n] === 'function') { | |
d[n] = null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj2string = function( obj, prefix ) { | |
var str = []; | |
for ( var prop in obj ) { | |
if ( obj.hasOwnProperty( prop ) ) { | |
var k = prefix ? prefix + '[' + prop + ']' : prop, v = obj[prop]; | |
str.push( typeof v === 'object' ? | |
obj2string( v, k ) : | |
encodeURIComponent( k ) + '=' + encodeURIComponent( v ) ); | |
} |