Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Chris Cai hkongm

🎯
Focusing
Block or report user

Report or block hkongm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View simple raf
// requestAnimationFrame的向下兼容处理
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(fn) {
setTimeout(fn, 17);
};
}
于是,动效绘制大致路数会变成这样:
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
View gist:07db6b4f1b376b24e9176cfda5a48a2e
# 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*
@hkongm
hkongm / 判断浏览器tab离开和进入.js
Created Nov 6, 2013
判断浏览器tab离开和进入。使用page visiblilty api实现。
View 判断浏览器tab离开和进入.js
(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 / 拦截浏览器滚动默认行为
Created Oct 11, 2013
拦截浏览器滚动默认行为
View 拦截浏览器滚动默认行为
$('body').on('touchmove', function(e){e.preventDefault()});
View 让所有的浏览器都支持 getElementsByClassName.js
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
View json 排序
var willSort = [
{
name:'shangwenhe',
age:25,
height:170
},
{
name:'zhangsan',
age:31,
height:169
View 函数聚合1
//取得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];
View 脚本 LoadScript
function loadScript(url, callback){
var script = document.createElement ("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" || script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
View URL解析
function ParseURL(arg){
var url = arg,
regexp = /([^\?]*)\??([^#]*)#(.*)/g,
regexpParam = /([^&]*)=([^&]*)/g,
urlExec = regexp.exec(url),
_host = urlExec[1],
_urlparam = urlExec[2],
_hashparam = urlExec[3];
View 控制台躲车游戏
(function(){
if(!window.console){window.console ={log:function(){}};return;}
var me = 19;
var Star = function(){
this.x=0;
this.speed = 1;
this.y=0;
}
var score = 0;
var strs = function(){
You can’t perform that action at this time.