Skip to content

Instantly share code, notes, and snippets.

View ifyour's full-sized avatar
🏁
问题解决师

明明 ifyour

🏁
问题解决师
View GitHub Profile
@ifyour
ifyour / querystring-to-obj.js
Last active June 12, 2017 06:42
利用正则表达式实现将查询字符串转成 Javscript 对象
const URL = "http://helloworld.com?user=Jack&pwd=123456&hobby=read";
const RE = /(\?|\&)([^=]+)\=([^&]+)/g;
let paramsObject = {};
URL.replace(RE, (match, p1, p2, p3) => {
paramsObject[p2] = p3;
});
console.log(paramsObject);
// will be { user: 'Jack', pwd: '123456', hobby: 'read' }
@ifyour
ifyour / get-random-num.js
Last active March 2, 2017 00:53
获取指定范围随机数
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
@ifyour
ifyour / horizontal-tip.html
Last active August 24, 2017 01:54
手机横屏友好提示// source http://jsbin.com/farahap
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>手机横屏友好提示</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
@ifyour
ifyour / dropbox-scss-css-style-guide.md
Created April 10, 2017 23:32 — forked from kxxoling/dropbox-scss-css-style-guide.md
Dropbox (S)CSS 样式指南中文翻译

Dropbox (S)CSS 样式指南翻译

开源许可

“Every line of code should appear to be written by a single person, no matter the number of contributors.” —@mdo

通用部分

反例

  • 避免在 CSS 使用 HTML 标签选择器
document.querySelectorAll('*').forEach(
function(domTarget) {
domTarget.addEventListener('click', function(e) {
console.log(e.target);
e.stopPropagation();
});
}
);
@ifyour
ifyour / maxLength.js
Last active June 12, 2017 03:30
基于 jQuery 的设置输入框长度的小插件, 用法: $('.input').maxLength(100,function(num,value){}); // num 剩余字数, value 变化的内容
// 适配 AMD 和 CMD 的模块化规范
;(function(factory){
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
@ifyour
ifyour / _extends.js
Last active June 12, 2017 03:23
原生 JavaScript 实现一个 extends 扩展函数.
// about assign :
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
// 对象的扩展, 本质上是一次复制操作, 将新增的属性或者方法 copy 到一个新的对象中
var _extends = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) { // 遍历传入的对象的属性
if (Object.prototype.hasOwnProperty.call(source, key)) { // 只操作该实例上的属性和方法, 避免循环原型
target[key] = source[key];
}
@ifyour
ifyour / Drag.html
Last active December 20, 2018 10:14
原生 JS 实现封装拖拽实例 // Demo: http://js.jirengu.com/hitoj
<!DOCTYPE html>
<html>
<head>
<title>Drag 实例</title>
<style type="text/css">
#box1,
#box2 {
width: 100px;
height: 100px;
@ifyour
ifyour / ellipsis.html
Last active August 24, 2017 01:53 — forked from anonymous/index.html
2行文字溢出显示省略, 支持 IE // Demo: http://js.jirengu.com/bozur
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.ellipsis-clamp {
line-height: 20px;
max-height: 40px;
@ifyour
ifyour / baidu-share.html
Last active August 24, 2017 01:52
配置百度分享, 自定义动态设置分享 URL // Demo : https://goo.gl/bZpqZ6
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.js"><\/script>
<style type="text/css">
.div_list_item {
margin-top: 30px;
}