Skip to content

Instantly share code, notes, and snippets.

View hkongm's full-sized avatar
🎯
Focusing

Chris Cai hkongm

🎯
Focusing
View GitHub Profile
//取得ID
var $ = function (id) {
return "string" == typeof id ? document.getElementByIdx_x(id) : id;
};
// 对象继承
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
var willSort = [
{
name:'shangwenhe',
age:25,
height:170
},
{
name:'zhangsan',
age:31,
height:169
var getElementsByClassName = function (searchClass, node,tag) {
if(document.getElementsByClassName){
var nodes = (node || document).getElementsByClassName(searchClass),result = [];
for(var i=0 ;node = nodes[i++];){
if(tag !== "*" && node.tagName === tag.toUpperCase()){
result.push(node)
}
}
return result
@hkongm
hkongm / 拦截浏览器滚动默认行为
Created October 11, 2013 07:49
拦截浏览器滚动默认行为
$('body').on('touchmove', function(e){e.preventDefault()});
@hkongm
hkongm / 判断浏览器tab离开和进入.js
Created November 6, 2013 06:41
判断浏览器tab离开和进入。使用page visiblilty api实现。
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
@hkongm
hkongm / gist:07db6b4f1b376b24e9176cfda5a48a2e
Created March 23, 2017 09:23 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
// requestAnimationFrame的向下兼容处理
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(fn) {
setTimeout(fn, 17);
};
}
于是,动效绘制大致路数会变成这样:
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');