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
/**
* 新窗口打开,并写入内容
* @param html
*/
function openWinHtml(html) {
let newWindow = window.open("", "newwin");
newWindow.document.write(html)
newWindow.document.close()
}
@function spaceBetween($itemPx, $itemCount, $wrapPx:750) {
@return #{(100 - $itemPx / $wrapPx * 100 * $itemCount) / ($itemCount + 1) + "%"};
}
@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>
@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 / 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 / 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 / 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 / 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 / marquee.js
Last active October 26, 2016 02:22
marquee.js
$.fn.marquee = function (options) {
var $that = this
var that = this[0]
if (!that) return
options = $.extend({}, {
speed: 50
}, options)
var timer = setInterval(marquee, options.speed)
@think2011
think2011 / dial.html
Last active October 31, 2016 09:48
canvass dial
<!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>