Skip to content

Instantly share code, notes, and snippets.

View lili21's full-sized avatar
🎯
Focusing

li.li lili21

🎯
Focusing
View GitHub Profile
@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 = {};
@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 / 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: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 / 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: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;
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;