Skip to content

Instantly share code, notes, and snippets.

View lili21's full-sized avatar
🎯
Focusing

li.li lili21

🎯
Focusing
View GitHub Profile
var BrowserDetect = {
init: function() {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function(data) {
for (var i = 0; i < data.length; i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
@lili21
lili21 / gist:7355283
Created November 7, 2013 14:20
smooth scrolling
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@lili21
lili21 / good parts functions
Last active December 29, 2015 07:28
javascript good parts function
//原型继承
if (typeof Object.beget !== 'function') {
Object.create = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
}
//var new_o = Object.create(old_o);
@lili21
lili21 / gist:7730183
Created December 1, 2013 09:02
fadein.onscroll
$(document).ready(function() {
/* Hide all elements outside the visible window */
$('body *').each( function(){
var top_of_object = $(this).position().top;
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( bottom_of_window < top_of_object ){
@lili21
lili21 / gist:3f33850c6a4f083c2df9
Last active August 29, 2015 14:07
angular watchers counts
(function () {
var root = angular.element(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);
@lili21
lili21 / gist:1e2821e56d3ca5dc17d7
Last active August 29, 2015 14:07
extend deep ,
function type(source) {
return Object.prototype.toString.call(source).replace(/^\[object (.+)\]/g, '$1').toLowerCase();
}
function forEach(source, callback) {
var type = type(source)
if (type === 'array')
for (var i = 0, l = source.length;i < l;i++) {
callback(source[i], i);
}
}
@lili21
lili21 / dataBind.js
Last active August 29, 2015 14:07 — forked from euforic/dataBind.js
/**
* two way data binding
*/
// create root scope
window.$rootScope = {};
Array.apply(null, {length: N}).map(Number.call, Number)
Array.apply(null, {length: N}).map(Function.call, Math.random)
@lili21
lili21 / gist:4c4edd06fd3f23d8c71e
Last active August 29, 2015 14:21
determine if an element is in the visible viewport, 判断元素是否在可视区域内
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@lili21
lili21 / b2b.js
Created June 1, 2015 09:13
base64 to blob
function b64ToUint6 (nChr) {
return nChr > 64 && nChr < 91 ?
nChr - 65
: nChr > 96 && nChr < 123 ?
nChr - 71
: nChr > 47 && nChr < 58 ?
nChr + 4
: nChr === 43 ?