Skip to content

Instantly share code, notes, and snippets.

View and80506's full-sized avatar

andy wu and80506

  • Netease
  • Hangzhou,China
View GitHub Profile
@and80506
and80506 / jQuery.isNative
Created December 9, 2013 06:55
jQuery.isNative
function isNative( fn ) {
return /^[^{]+\{\s*\[native \w/.test( fn + "" );
}
@and80506
and80506 / jQuery.support
Created December 9, 2013 07:30
jQuery.support 实现
/**
* Support testing using an element
* @param {Function} fn Passed the created div and expects a boolean result
*/
function assert( fn ) {
var div = document.createElement("div");
try {
return !!fn( div );
} catch (e) {
@and80506
and80506 / isOnViewPort
Last active December 30, 2015 21:49
Check if element is visible on viewport
var isOnViewPort = (function() {
var compatMode = document.compatMode;
function posY(elm) {
var test = elm, top = 0;
while(!!test && test.tagName.toLowerCase() !== "body") {
top += test.offsetTop;
test = test.offsetParent;
}
@and80506
and80506 / guid
Created August 26, 2014 05:39
guid
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
@and80506
and80506 / 多行文本溢出显示省略号
Created August 28, 2014 09:42
多行文本溢出显示省略号
{
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
// hey, everybody! it's a tiny Web server!
// instead of a bunch of foo = reqire("foo")
// list our required modules and loop through
var r = ["fs", "http", "path", "url"];
for (var i = 0; i < r.length; i++) {
global[r[i]] = require(r[i]);
}
// some constants