Skip to content

Instantly share code, notes, and snippets.

View zhuzhuaicoding's full-sized avatar

zhuzhu_coder zhuzhuaicoding

View GitHub Profile
@zhuzhuaicoding
zhuzhuaicoding / find-pos
Created October 27, 2012 06:24
Updated "find position" script
function findPos(obj) {
var curleft = curtop = 0, scr = obj, fixed = false;
while ((scr = scr.parentNode) && scr != document.body) {
curleft -= scr.scrollLeft || 0;
curtop -= scr.scrollTop || 0;
if (getStyle(scr, "position") == "fixed") fixed = true;
}
if (fixed && !window.opera) {
var scrDist = scrollDist();
curleft += scrDist[0];
@zhuzhuaicoding
zhuzhuaicoding / fixed-style-ie6
Created October 27, 2012 07:10
fixed use css hack fro ie6
top:expression(documentElement.scrollTop + documentElement.clientHeight - this.clientHeight-85 + 'px')
http://t.163.com/
position: absolute; top: expression(((document.documentElement.scrollTop || document.body.scrollTop) + (document.documentElement.clientHeight || document.body.clientHeight) - this.offsetHeight) + "px");
http://www.seabreezecomputers.com/tips/fixed-div.htm
_top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat')
? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight)
@zhuzhuaicoding
zhuzhuaicoding / function-util
Created October 30, 2012 05:09
Util function
(function(util) {
var toString = Object.prototype.toString;
var AP = Array.prototype;
util.isString = function(val) {
return toString.call(val) === '[object String]';
};
@zhuzhuaicoding
zhuzhuaicoding / gist:3979590
Created October 30, 2012 10:52
fixed element using js
// Function to get the amount of pixels scrolled
// Copied from the Internet
function getScrollXY() {
var scrOfX = 0, scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//DOM compliant
@zhuzhuaicoding
zhuzhuaicoding / semaphore.js
Created October 30, 2012 14:43 — forked from ricardobeat/semaphore.js
simple semaphore for parallel async execution, with error handling.
function queue(name){
queue.q[name]++ || (queue.q[name] = 1);
return function(err){
if (err && queue.e[name]) queue.e[name](err);
else if (err) throw err;
process.nextTick(function(){
queue.q[name]--;
queue.check(name);
});
}
@zhuzhuaicoding
zhuzhuaicoding / gist:3984655
Created October 31, 2012 03:38
check is a number
var isnan = /^(NaN|-?Infinity)$/;
function isNumeric(num) {
return !isnan.test(+num);
}
function is(o, type) {
type = String(type).toLowerCase();
return (type == "null" && o === null) ||
(type == typeof o) ||
(type == "object" && o === Object(o)) ||
(type == "array" && Array.isArray && Array.isArray(o)) ||
Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type;
}
is(function(){}, "object"); // true
var addEvent=(function(){
if(document.addEventListener){
return function(el,type,fn){
if(el.length){
for(var i=0;i<el.length;i++){
addEvent(el[i],type,fn);
}
}else{
el.addEventListener(type,fn,false);
}
@zhuzhuaicoding
zhuzhuaicoding / gist:3998837
Created November 2, 2012 05:07
addEvent basic
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);//DOM2.0
return true;
}
else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);//IE5+
return r;
}
else {
@zhuzhuaicoding
zhuzhuaicoding / gist:4076125
Created November 15, 2012 01:44
getStyle
/*
Example call of the function:
getStyle(document.getElementById("container"), "font-size");
*/
// The regular version
function getStyle(oElm, strCssRule){
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){