Skip to content

Instantly share code, notes, and snippets.

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

曾浩 think2011

🏠
Working from home
  • Guangzhou, China
View GitHub Profile
@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 / padNumber.js
Last active October 10, 2016 09:02
数字补零
//改自:http://blog.csdn.net/aimingoo/article/details/4492592
var len = ('' + num).length;
return (Array(
fill > len ? fill - len + 1 || 0 : 0
).join(0) + num);
@think2011
think2011 / umd.js
Created September 30, 2016 01:36
umd define
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define([], factory)
} else if (typeof exports === 'object') {
// Node, CommonJS
module.exports = factory()
} else {
// Window
root.collisionChecker = factory()
@think2011
think2011 / drag.js
Created September 29, 2016 09:14
九宫格拖拽
$(function () {
function Pointer(x, y) {
this.x = x;
this.y = y;
}
function Position(left, top) {
this.left = left;
this.top = top;
}
@think2011
think2011 / gist:c37671d1a97c67ba3809898ce28113ff
Created September 1, 2016 10:28
浏览器兼容性提示
<script>
// 放在body内
if (navigator.userAgent.toLowerCase().indexOf("applewebkit/") < 0) {
var html = '\n<div style="position: absolute; width: 100%;height: 100%; z-index: 1000000;">\n \n <div style="\n background: #FFF3E1;\n padding: 20px;\n text-align: center;\n font-size: 15px;\n position: relative;\n z-index: 1000;\n color: #777;">\n <span style="color:#FF9800; ">▶</span> 很抱歉,无线编辑器暂不支持您的浏览器内核,请您\n <a style="color: #2196F3;"\n href="http://chrome.360.cn/test/core/">升级浏览器</a>\n 后再使用。\n </div>\n \n <div style="background: #eee;position: absolute;width: 100%;height: 100%;z-index: 10000;opacity: .7;"></div>\n</div>';
document.body.innerHTML = html
}
</script>
@function spaceBetween($itemPx, $itemCount, $wrapPx:750) {
@return #{(100 - $itemPx / $wrapPx * 100 * $itemCount) / ($itemCount + 1) + "%"};
}
/**
* 新窗口打开,并写入内容
* @param html
*/
function openWinHtml(html) {
let newWindow = window.open("", "newwin");
newWindow.document.write(html)
newWindow.document.close()
}
@think2011
think2011 / getValueOfPath.js
Last active March 17, 2016 07:01
根据obj的path获得数据
/**
* 根据obj的path获得数据
* @param obj {Object}
* @param path {String}
* @returns {*}
*/
function getValueOfPath(obj, path) {
var pathArray = path.split('.')
var currentPath = pathArray.shift()
@think2011
think2011 / Pager.js
Created February 20, 2016 15:16
生成用于angular的分页组件的对象结构
export default angular.module('dtcloud.directive.pager', [])
.factory('Pager', PagerFactory)
.directive('pager', PagerDirective)
/**
* 生成一个适用于 PagerDirective 的对象结构
* @returns {Pager}
* @constructor
*/
@think2011
think2011 / reverse.js
Created February 17, 2016 09:43
递归的方式反转字符串
var s = '123456';
function reverse (s) {
let _s = [...s];
return s ? _s.pop() + reverse(_s.join('')) : '';
}
reverse(s);