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 / CreateDom.js
Last active August 29, 2015 14:14
创建一个绝对定位的相对定位DOM
;(function () {
/**
* 创建一个绝对定位的相对定位DOM
* @param html
* @param parent
* @constructor
*/
function CreateDom (html, parent) {
this.dom = document.createElement('div');
this.parent = document.querySelector(parent);
window.log = function () {
var args = [].slice.call(arguments);
args.forEach(function (v, k) {
if(typeof v === 'object') args[k] = JSON.stringify(v);
});
alert([].join.call(args, '\n'));
};
@think2011
think2011 / ChangeState.js
Last active August 29, 2015 14:16
元素切换机
/**
* 切换元素显示状态
*
* @param btns {object} 定义要切换的元素组
* @constructor
* @example
var actions = new ChangeState({ a: ['#box', '#box2'], b: ['.box3']);
actions.a();
*/
function ChangeState(btns) {
@think2011
think2011 / previewImg.js
Created March 16, 2015 09:37
兼容IE8 - 9 的图片预览
function previewImg(el, inputFile) {
el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";
el.filters("DXImageTransform.Microsoft.AlphaImageLoader").src = inputFile.value;
}
@think2011
think2011 / getParams.js
Last active August 29, 2015 14:17
获取url参数 getParams.js
window.QUERYSTRING = (function () {
var params = {},
pair = (window.location.search.substr(1)).split('&');
if (pair[0]) {
for (var i = 0; i < pair.length; i++) {
var pos = pair[i].split('=');
params[pos[0]] = decodeURIComponent(pos[1]);
}
window.getRouteParams = function () {
var params = [],
routes = (window.location.pathname).split('/');
for(var i = 0; i < routes.length; i++) {
if(routes[i]) params.push(routes[i]);
}
return params;
};
@think2011
think2011 / close.js
Last active August 29, 2015 14:18
关闭窗口
window.closeWindow = function () {
window.open('', '_self', '');
window.close();
};
@think2011
think2011 / PollAjax.js
Last active August 29, 2015 14:19
PollAjax
/**
* 轮询ajax请求
* @param fn
* @param [delay = 500]
* @constructor
* @example
* var pa = new PollAjax(function (continueNext, done) {
$.get('../')
.done(function (data) {
if (data.success) {
@think2011
think2011 / limit-max.js
Created May 21, 2015 04:12
directive 限制输入的最大数,最小数无法设置,因为删除时无法判断
var app = angular.module('limit-max', []);
/**
* 限制输入的最大数,最小数无法设置,因为删除时无法判断
* @example
* <input ng-model="xx" type="number" limit-max="100">
*/
app.directive('limitMax', function() {
return {
restrict : 'A',
@think2011
think2011 / ng-tools.js
Last active August 29, 2015 14:22
ng-tools
(function() {
var app = angular.module('tools', []);
/**
* syncCheckboxModalToArray
* @$scope
* @modal string
* @array string
*/
app.factory('syncCheckboxModalToArray', function() {