Skip to content

Instantly share code, notes, and snippets.

View think2011's full-sized avatar
🏠
Working from home

曾浩 think2011

🏠
Working from home
View GitHub Profile
@think2011
think2011 / throttle&debounce.js
Created April 1, 2017 10:04
防抖和节流
function debounce(method, context) {
clearTimeout(method.tId);
method.tId = setTimeout(function() {
method.call(context);
}, 1000);
}
var throttle = function (action, delay){
var last = 0;
return function(){
@think2011
think2011 / 合并和排序.js
Created January 16, 2017 04:32
合并和排序
var a = [1, 2, 45, 88];
var b = [3, 7, 8];
var flag = 0;
for (let i = 0; i < b.length; i++) {
if (b[i] <= a[flag] || flag > a.length) {
a.splice(flag, 0, b[i]);
} else {
i--;
@think2011
think2011 / AirScroll.js
Created January 4, 2017 16:29
AirScroll
export default class AirScroll {
constructor(options, updateCb) {
this.container = options.container
this.itemHeight = options.itemHeight
this.containerHeight = options.containerHeight
this.sourceItems = options.items
this.items = []
this.updateCb = updateCb
this.init()
@think2011
think2011 / ng-virual-list.js
Created January 4, 2017 10:05
virtual list
angular.module('virtualListApp')
.directive('uiVirtualList',
[function () {
'use strict';
return {
restrict: 'E',
require: "ngModel",
templateUrl: "views/directives/ui-virtual-list.html",
scope: {
uiDataProvider: '=',
function outerClick(selector, fn) {
$(document).on("click", function (event) {
var isHit = $(event.target).closest(selector).length
if (!isHit) fn.call(fn, event)
})
return function () {
$(document).off('click', fn)
}
@think2011
think2011 / stats.js
Last active November 18, 2016 11:58
检测FPS
/* stats.js - http://github.com/mrdoob/stats.js*/
var Stats = function () {
var l = Date.now(), m = l, g = 0, n = Infinity, o = 0, h = 0, p = Infinity, q = 0, r = 0, s = 0, f = document.createElement("div");
f.id = "stats";
f.addEventListener("mousedown", function (b) {
b.preventDefault();
t(++s % 2)
}, !1);
f.style.cssText = "width:80px;opacity:0.9;cursor:pointer";
var a = document.createElement("div");
@think2011
think2011 / scene.scss
Last active November 13, 2016 04:03
css实现的tabs
[class^=scene-] {
transform: translate3d(0, 0, 0);
transition: .3s ease;
display: flex;
flex-flow: row nowrap;
@for $i from 0 through 5 {
&.scene-#{$i} {
transform: translate3d(#{-($i * 100%)}, 0, 0);
}
@think2011
think2011 / Checker.js
Last active November 6, 2016 15:34
checker 选择反选
class Checker {
/**
* 生成一个 checker
* @param context 是一个object,跟itemKey配合得到items
* @param itemKey context中的items的key
* @param idKey 用于匹配的值
* @example
this.checker = new Checker({
context: this,
itemKey: 'items',
@think2011
think2011 / zoomSize.js
Last active November 2, 2016 12:06
比例尺寸计算
/**
* 比例尺寸计算
*
* @param options
* @param options.w
* @param options.h
* @param [options.newW]
* @param [options.newH]
* @param [options.max]
* @returns {object}
@think2011
think2011 / dial2.html
Created October 31, 2016 17:17
dial2
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="demo.css">
<!--<script src="index.js"></script>-->
</head>
<style>