Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

曾浩 think2011

🏠
Working from home
View GitHub Profile
@think2011
think2011 / CreateDom.js
Last active Aug 29, 2015
创建一个绝对定位的相对定位DOM
View CreateDom.js
;(function () {
/**
* 创建一个绝对定位的相对定位DOM
* @param html
* @param parent
* @constructor
*/
function CreateDom (html, parent) {
this.dom = document.createElement('div');
this.parent = document.querySelector(parent);
View log.js
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 Aug 29, 2015
元素切换机
View ChangeState.js
/**
* 切换元素显示状态
*
* @param btns {object} 定义要切换的元素组
* @constructor
* @example
var actions = new ChangeState({ a: ['#box', '#box2'], b: ['.box3']);
actions.a();
*/
function ChangeState(btns) {
@think2011
think2011 / previewImg.js
Created Mar 16, 2015
兼容IE8 - 9 的图片预览
View previewImg.js
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 Aug 29, 2015
获取url参数 getParams.js
View 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 Sep 30, 2016
string render
View render.js
/**
* 替换字符串 ${}
* @param obj
* @returns {String}
* @example
* '我是${str}'.render({str: '测试'});
*/
String.prototype.render = function (obj) {
var str = this, reg;
View getRouteParams.js
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 Aug 29, 2015
关闭窗口
View close.js
window.closeWindow = function () {
window.open('', '_self', '');
window.close();
};
@think2011
think2011 / Watermark.js
Created Apr 11, 2015
给图片加水印
View Watermark.js
/**
* 给图片打文字水印
* @param img Object||String
* @param opt
* @constructor
*/
function Watermark(img, opt) {
this.opt = opt;
View PollAjax.js
/**
* 轮询ajax请求
* @param fn
* @param [delay = 500]
* @constructor
* @example
* var pa = new PollAjax(function (continueNext, done) {
$.get('../')
.done(function (data) {
if (data.success) {