Skip to content

Instantly share code, notes, and snippets.

View xxjinwei's full-sized avatar
💻
Working...

Celile Fulwood xxjinwei

💻
Working...
View GitHub Profile
@xxjinwei
xxjinwei / offset.js
Created December 17, 2013 03:29
get offset
function getOffset (ele) {
var box = ele.getBoundingClientRect();
return {
top: box.top + (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0),
left: box.left + (window.pageXOffset || document.documentElement.scrollLeft) - (document.documentElement.clientLeft || 0)
};
};
@xxjinwei
xxjinwei / text-overflow.css
Created December 11, 2013 10:02
css text overflow
/**
referrence:http://leeiio.me/text-overflow-ellipsis/
*/
.overflow {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
@xxjinwei
xxjinwei / req.js
Last active December 29, 2015 15:09
ie6 http url max length
//Fuck ie6!!!!
//url length >= 2084 returns error code 0x7a
(function(length) {
var url = "http://zhushou.sogou.com/data/data.html?",
len = url.length,
str = new Array(length+1-len).join("u"),
img = new Image();
img.src = url+str;
@xxjinwei
xxjinwei / detect ie 8 and less.js
Last active December 27, 2015 23:49
ie浏览器检测
//ie8及以下浏览器
if (window.attachEvent && !window.addEventListener) {
// "bad" IE
}
//ie7及以下浏览器
if (window.attachEvent && !document.querySelector) {
// "bad" IE
}
@xxjinwei
xxjinwei / clone.js
Last active December 27, 2015 09:09
deepcopy from Snap.svg
/**
https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js#L214
*/
function clone(obj) {
if (typeof obj == "function" || Object(obj) !== obj) {
return obj;
@xxjinwei
xxjinwei / radius.css
Created September 22, 2013 06:44
border-radius
/*
http://css-tricks.com/almanac/properties/b/border-radius/
*/
.round {
/* Safari 3-4, iOS 1-3.2, Android 1.6- */
-webkit-border-radius: 12px;
/* Firefox 1-3.6 */
-moz-border-radius: 12px;
@xxjinwei
xxjinwei / transparent.css
Last active December 23, 2015 15:29
cross-broswer transparent
/*
http://css-tricks.com/css-transparency-settings-for-all-broswers/
*/
.transparent {
zoom: 1;
filter: alpha(opacity=50);
opacity: 0.5;
}
@xxjinwei
xxjinwei / insertArray.js
Created September 8, 2013 15:31
insert an array to another array
//https://code.google.com/p/jslibs/wiki/JavascriptTips#Insert_an_array_in_another_array
var a = [1,2,3,7,8,9]
var b = [4,5,6]
var insertIndex = 3;
a.splice.apply(a, Array.concat(insertIndex, 0, b));
Print(a); // prints: 1,2,3,4,5,6,7,8,9
@xxjinwei
xxjinwei / leftPad.js
Last active December 22, 2015 14:19
leftPad的不同实现思路
//copy 字符串
//这种每次加一个“0”的方式有些慢,可以参考underscore.string的优化
function leftPad(numstr,length) {
while(numstr.length < length) {
numstr = "0"+numstr;
}
return numstr;
}
@xxjinwei
xxjinwei / match.js
Created September 2, 2013 16:11
javascript match
chop: function(str, step){
if (str == null) return [];
str = String(str);
step = ~~step;
return step > 0 ? str.match(new RegExp('.{1,' + step + '}', 'g')) : [str];
}