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]);
}
@think2011
think2011 / render.js
Last active September 30, 2016 07:13
string render
/**
* 替换字符串 ${}
* @param obj
* @returns {String}
* @example
* '我是${str}'.render({str: '测试'});
*/
String.prototype.render = function (obj) {
var str = this, reg;
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 / Watermark.js
Created April 11, 2015 09:41
给图片加水印
/**
* 给图片打文字水印
* @param img Object||String
* @param opt
* @constructor
*/
function Watermark(img, opt) {
this.opt = opt;
@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) {