BOM的UTF-8img input br hr 等class & id-分隔<li>用于<ul>或<ol>下<dd> <dt> 用于 <dl>下<thead> <tbody> <tfoot> <tr> <td> 用于 <table> 下<a>里不可以嵌套交互式元素<a>、<button>、<select>等;<p>里不可以嵌套块级元素<div>、<h1>~<h6>、<p>、<ul>/<ol>/<li>、<dl>/<dt>/<dd>、<form>等。apple-touch-icon 图片自动处理成圆角和高光等效果;apple-touch-icon-precomposed 禁止系统自动添加效果,直接显示设计原图;<!DOCTYPE html><lang="zh-cmn-Hans"><head>标签的第一个子元素) <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">SEO优化 <meta name="keywords" content="your keywords"> <meta name="description" content="your description"> <meta name="author" content="author,email address"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" href="path/to/favicon.ico">HEAD模板
<!DOCTYPE html><html lang="zh-cmn-Hans"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Style Guide</title>
<meta name="description" content="不超过150个字符">
<meta name="keywords" content="">
<meta name="author" content="name, email@gmail.com">
<!-- 为移动设备添加 viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- iOS 图标 -->
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png">
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<link rel="shortcut icon" href="path/to/favicon.ico"></head>HTML标签语义化
段落<b> 为样式加粗而加粗
<storng> | 为强调内容而加粗
<i> | 为样式倾斜而倾斜
<em> | 为强调内容而倾斜
<code> | 代码标识
<abbr> | 缩写
Class ID叠加使用{ 前添加一个空格;} 应单独成行;: 后应添加一个空格;; 结尾;@importa:link -> a:visited -> a:hover -> a:active(LoVeHAte)/* ==========================================================================
组件块
============================================================================ *//* 子组件块
============================================================================ */由于定位(positioning)可以从正常的文档流中移除元素,并且还能覆盖盒模型(box model)相关的样式,因此排在首位。盒模型决定了组件的尺寸和位置,因此排在第二位。其他属性只是影响组件的内部(inside)或者是不影响前两组属性。
.declaration-order { /* Positioning */
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 100; /* Box model */
display: block;
box-sizing: border-box;
width: 100px;
height: 100px;
padding: 10px;
border: 1px solid #e5e5e5;
border-radius: 3px;
margin: 10px;
float: right;
overflow: hidden; /* Typographic */
font: normal 13px "Helvetica Neue", sans-serif;
line-height: 1.5;
text-align: center; /* Visual */
background-color: #f5f5f5;
color: #fff;
opacity: .8; /* Other */
cursor: pointer;
}内文字体
p { font-family: "Georgia", "Times New Roman", "Songti SC", "SimSun", serif; }标题字体
h1, h2, h3, h4, h5, h6 { font-family: "Lucida Grande", "Helvetica Neue", "Arial", "Hiragino Sans GB", "Noto Sans CJK SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Microhei", sans-serif; }将内文以 16px 作为字号
标题 h1, h2, h3, h4, h5, h6 以 16px 作为字号基础,按同比例的递减
p { font-size: 16px; }h1 { font-size: 2em; }h2 { font-size: 1.8em; }h3 { font-size: 1.6em; }h4 { font-size: 1.4em; }h5, h6 { font-size: 1.2em; }将内文以 1.7em 作为行高 标题 h1, h2, h3, h4, h5, h6 以 1.5em 作为行高.
p { line-height: 1.7em; }h1, h2, h3, h4, h5, h6 { line-height: 1.5em; }p { margin-bottom: 1.7em; }h1, h2, h3, h4, h5, h6 { margin-top: .7em; margin-bottom: 0.2em;
}p {text-align: justify;text-justify: inter-ideographic;
}p { word-break: break-all; }.less不得省略, 用双引号@base-url: "http://assets.fnord.com"; background-image: url("@{base-url}/images/bg.png");-分离 .like-button .search-form .article-card-.-wide .-short .-disabled .title.-small常见class关键词:
简单规则
//, 避免使用/*...*/@inner标识/**
* 函数描述
*
* @param {string} p1 参数1的说明
* @param {string} p2 参数2的说明,比较长
* 那就换行了.
* @param {number=} p3 参数3的说明(可选)
* @return {Object} 返回值描述
*//**
* @fileoverview Description of file, its uses and information
* about its dependencies.
* @author user@meizu.com (Firstname Lastname)
* Copyright 2009 Meizu Inc. All Rights Reserved.
*/_开头_分隔_分隔function Engine(options) {}function getStyle(element) {}var isReady = false; var hasMoreCommands = false;var loadingData = ajax.get('url'); loadingData.then(callback);jQuery社区习惯冲突 3.尽量写全不用缩写,除非下表中已经约定的)常用词 | 说明 |
|---|---|
options | 表示选项,与 jQuery 社区保持一致,不要用 config, opts 等 |
active | 表示当前,不要用 current 等 |
index | 表示索引,不要用 idx 等 |
trigger | 触点元素 |
triggerType | 触发类型、方式 |
context | 表示传入的 this 对象 |
object | 推荐写全,不推荐简写为 o, obj 等 |
element | 推荐写全,不推荐简写为 el, elem 等 |
length | 不要写成 len, l |
prev | previous 的缩写 |
next | next 下一个 |
constructor | 不能写成 ctor |
easing | 示动画平滑函数 |
min | minimize 的缩写 |
max | maximize 的缩写 |
DOM | 不要写成 dom, Dom |
.hbs | 使用 hbs 后缀表示模版 |
btn | button 的缩写 |
link | 超链接 |
title | 主要文本 |
img | 图片路径(img标签src属性) |
dataset | html5 data-xxx 数据接口 |
theme | 主题 |
className | 类名 |
classNameSpace | class 命名空间 |
typeofinstanceof== nullnull undefined '' 0'0' [] {}for-in循环只用于object/map/hash遍历, 因为Array上使用for-in循环会对所有出现在原型上的对象进行遍历if...else&& || 设置默认值和替代多个if嵌套判断.test()和.exec()。不准用"string".match()$开头, 并缓存到本地变量中复用, 使用驼峰命名法命名.find()方法性能会更好array.join('') >+ > .append()$("#myLink").on("click.mySpecialClick", myEventHandler);
$("#myLink").unbind("click.mySpecialClick");// Not recommended$("#list a").on("click", myClickHandler);// Recommended$("#list").on("click", "a", myClickHandler);CSS不要写在jQuery里面jQuery 实现动画slideUp/Down() fadeIn/fadeOut() 等方法;animate()方法;jQuery 插件模板
// jQuery Plugin Boilerplate// A boilerplate for jumpstarting jQuery plugins development// version 1.1, May 14th, 2011// by Stefan Gabos// remember to change every instance of "pluginName" to the name of your plugin!(function($) { // here we go!
$.pluginName = function(element, options) { // plugin's default options
// this is private property and is accessible only from inside the plugin
var defaults = {
foo: 'bar', // if your plugin is event-driven, you may provide callback capabilities
// for its events. execute these functions before or after events of your
// plugin, so that users may customize those particular events without
// changing the plugin's code
onFoo: function() {}
} // to avoid confusions, use "plugin" to reference the
// current instance of the object
var plugin = this; // this will hold the merged default, and user-provided options
// plugin's properties will be available through this object like:
// plugin.settings.propertyName from inside the plugin or
// element.data('pluginName').settings.propertyName from outside the plugin,
// where "element" is the element the plugin is attached to;
plugin.settings = {} var $element = $(element), // reference to the jQuery version of DOM element
element = element; // reference to the actual DOM element
// the "constructor" method that gets called when the object is created
plugin.init = function() { // the plugin's final properties are the merged default and
// user-provided options (if any)
plugin.settings = $.extend({}, defaults, options); // code goes here
} // public methods
// these methods can be called like:
// plugin.methodName(arg1, arg2, ... argn) from inside the plugin or
// element.data('pluginName').publicMethod(arg1, arg2, ... argn) from outside
// the plugin, where "element" is the element the plugin is attached to;
// a public method. for demonstration purposes only - remove it!
plugin.foo_public_method = function() { // code goes here
} // private methods
// these methods can be called only from inside the plugin like:
// methodName(arg1, arg2, ... argn)
// a private method. for demonstration purposes only - remove it!
var foo_private_method = function() { // code goes here
} // fire up the plugin!
// call the "constructor" method
plugin.init();
} // add the plugin to the jQuery.fn object
$.fn.pluginName = function(options) { // iterate through the DOM elements we are attaching the plugin to
return this.each(function() { // if plugin has not already been attached to the element
if (undefined == $(this).data('pluginName')) { // create a new instance of the plugin
// pass the DOM element and the user-provided options as arguments
var plugin = new $.pluginName(this, options); // in the jQuery version of the element
// store a reference to the plugin object
// you can later access the plugin and its methods and properties like
// element.data('pluginName').publicMethod(arg1, arg2, ... argn) or
// element.data('pluginName').settings.propertyName
$(this).data('pluginName', plugin);
}
});
}
})(jQuery);let取代varlet const优先使用const(所有的函数应设置为const常量,let表示的变量,只应出现在单线程运行的代码中,不能是多线程共享的,这样有利于保证线程安全。)const [first, second] = [1, 2];Object.assign()...拷贝数组Array.from()将类数组对象转为数组(()=>{console.log('a');})()thisFunction.prototype.bind,不应再用self/_this/that绑定this。arguments变量,使用rest运算符(...)代替。Map结构Object。如果只是需要key:value的数据结构,使用Map。因为Map有内建的遍历机制。class取代prototype操作extends实现继承,这样不会有破坏instanceof运算的危险。import 取代 requireexport 取代 module.exportsexport default,如果模块有多个输出值,就不使用export default,不要export default与普通的export同时使用。export default)。$ npm i -g eslint$ npm i -g eslint-config-airbnb.eslintrc文件,配置ESLint。{"extends": "eslint-config-airbnb"}