diff --git a/.gitignore b/.gitignore index 496ee2c..086538f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +_book diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..954458c --- /dev/null +++ b/AUTHORS @@ -0,0 +1,13 @@ +Li Xinyang +Li Xinyang +rwang23 +hcy003 +Fred.W. +tinglin92 +Tinglin +Sylvia Zhang +leikn +The Gitter Badger +Osub <814566123@qq.com> +Chenyu +nifanle diff --git a/Booklist.md b/Booklist.md index 389c7c1..4a636d6 100644 --- a/Booklist.md +++ b/Booklist.md @@ -2,14 +2,14 @@ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* -- [Booklist](#booklist) +- [书单](#%E4%B9%A6%E5%8D%95) - [HTML](#html) - [CSS](#css) - [JavaScript](#javascript) -# Booklist +# 书单 ## HTML @@ -25,3 +25,8 @@ N/A - DOM Scripting: Web Design with JavaScript and the Document Object Model - AdvancED DOM Scripting: Dynamic Web Design Techniques - JavaScript: The Definitive Guide + +## Version Control + +- [Git 简明指南](http://rogerdudler.github.io/git-guide/index.zh.html) +- [Git Pro](https://git-scm.com/book/en/v2) diff --git a/DO_NOT_OPEN/Quiz0.html b/DO_NOT_OPEN/Quiz0.html deleted file mode 100644 index 35f8f7a..0000000 --- a/DO_NOT_OPEN/Quiz0.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - 图书畅销榜 - - - - - - - - - diff --git a/DO_NOT_OPEN/Quiz1.html b/DO_NOT_OPEN/Quiz1.html deleted file mode 100644 index c079e7f..0000000 --- a/DO_NOT_OPEN/Quiz1.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - 运费详情 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
运费详情
地域寄达地首重(元/1000g)续重(元/1000g)
一区浙江、上海、江苏61
江西、安徽71
二区吉利、黑龙江、云南106
三区新疆、西藏1510
- - \ No newline at end of file diff --git a/DO_NOT_OPEN/Quiz3.html b/DO_NOT_OPEN/Quiz3.html deleted file mode 100644 index 25601fe..0000000 --- a/DO_NOT_OPEN/Quiz3.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - 表单 - - - -
-
- - -
-
- - -
-
- - -
-
- - - - - -
-
- - - - - -
-
- - -
- -
- - \ No newline at end of file diff --git a/JavascriptDesignPattern/JavascriptDesignPattern.md b/JavascriptDesignPattern/JavascriptDesignPattern.md deleted file mode 100644 index 353c511..0000000 --- a/JavascriptDesignPattern/JavascriptDesignPattern.md +++ /dev/null @@ -1,1847 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [JavaScript 程序设计](#javascript-%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1) - - [JavaScript 介绍](#javascript-%E4%BB%8B%E7%BB%8D) - - [调试器](#%E8%B0%83%E8%AF%95%E5%99%A8) - - [基本语法](#%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95) - - [变量标示符](#%E5%8F%98%E9%87%8F%E6%A0%87%E7%A4%BA%E7%AC%A6) - - [关键字与保留字](#%E5%85%B3%E9%94%AE%E5%AD%97%E4%B8%8E%E4%BF%9D%E7%95%99%E5%AD%97) - - [字符敏感](#%E5%AD%97%E7%AC%A6%E6%95%8F%E6%84%9F) - - [严格模式](#%E4%B8%A5%E6%A0%BC%E6%A8%A1%E5%BC%8F) - - [注释](#%E6%B3%A8%E9%87%8A) - - [类型系统](#%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F) - - [标准类型](#%E6%A0%87%E5%87%86%E7%B1%BB%E5%9E%8B) - - [变量转换表](#%E5%8F%98%E9%87%8F%E8%BD%AC%E6%8D%A2%E8%A1%A8) - - [类型识别](#%E7%B1%BB%E5%9E%8B%E8%AF%86%E5%88%AB) - - [内置对象](#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1) - - [标准内置对象](#%E6%A0%87%E5%87%86%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1) - - [Object](#object) - - [Object.create](#objectcreate) - - [Object.prototype.toString](#objectprototypetostring) - - [Object.prototype.hasOwnProperty](#objectprototypehasownproperty) - - [Boolean](#boolean) - - [String](#string) - - [String.prototype.indexOf](#stringprototypeindexof) - - [String.prototype.replace](#stringprototypereplace) - - [String.prototype.split](#stringprototypesplit) - - [Number](#number) - - [Number.prototype.toFixed](#numberprototypetofixed) - - [Array](#array) - - [Array.prototype.splice](#arrayprototypesplice) - - [Array.prototype.forEach](#arrayprototypeforeach) - - [Function](#function) - - [自定义对象构造器](#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%B9%E8%B1%A1%E6%9E%84%E9%80%A0%E5%99%A8) - - [Function.prototype.apply](#functionprototypeapply) - - [Function.prototype.bind](#functionprototypebind) - - [子类构造器](#%E5%AD%90%E7%B1%BB%E6%9E%84%E9%80%A0%E5%99%A8) - - [函数调用](#%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8) - - [函数参数](#%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0) - - [arguments](#arguments) - - [值专递](#%E5%80%BC%E4%B8%93%E9%80%92) - - [函数重载](#%E5%87%BD%E6%95%B0%E9%87%8D%E8%BD%BD) - - [RegExp](#regexp) - - [RegExp.prototype.test](#regexpprototypetest) - - [Date](#date) - - [标准内置对象](#%E6%A0%87%E5%87%86%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-1) - - [Math](#math) - - [Math.floor](#mathfloor) - - [Math.random](#mathrandom) - - [JSON](#json) - - [JSON.stringify](#jsonstringify) - - [JSON.parse](#jsonparse) - - [全局对象](#%E5%85%A8%E5%B1%80%E5%AF%B9%E8%B1%A1) - - [NaA](#naa) - - [parseInt](#parseint) - - [eval](#eval) - - [encodedURIComponent](#encodeduricomponent) - - [变量作用域](#%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F) - - [作用域介绍](#%E4%BD%9C%E7%94%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D) - - [静态作用域](#%E9%9D%99%E6%80%81%E4%BD%9C%E7%94%A8%E5%9F%9F) - - [动态作用域](#%E5%8A%A8%E6%80%81%E4%BD%9C%E7%94%A8%E5%9F%9F) - - [JavaScript 变量作用域](#javascript-%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F) - - [词法环境](#%E8%AF%8D%E6%B3%95%E7%8E%AF%E5%A2%83) - - [组成](#%E7%BB%84%E6%88%90) - - [创建](#%E5%88%9B%E5%BB%BA) - - [结构](#%E7%BB%93%E6%9E%84) - - [关于词法环境的问题](#%E5%85%B3%E4%BA%8E%E8%AF%8D%E6%B3%95%E7%8E%AF%E5%A2%83%E7%9A%84%E9%97%AE%E9%A2%98) - - [with 语句](#with-%E8%AF%AD%E5%8F%A5) - - [try-catch 句法](#try-catch-%E5%8F%A5%E6%B3%95) - - [带名称的函数表达式](#%E5%B8%A6%E5%90%8D%E7%A7%B0%E7%9A%84%E5%87%BD%E6%95%B0%E8%A1%A8%E8%BE%BE%E5%BC%8F) - - [表达式与运算符](#%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%B8%8E%E8%BF%90%E7%AE%97%E7%AC%A6) - - [表达式](#%E8%A1%A8%E8%BE%BE%E5%BC%8F) - - [运算符](#%E8%BF%90%E7%AE%97%E7%AC%A6) - - [===](#) - - [==](#) - - [例外规则](#%E4%BE%8B%E5%A4%96%E8%A7%84%E5%88%99) - - [!](#) - - [&&](#&&) - - [||](#%7C%7C) - - [元算符优先级(Operator Precedence)](#%E5%85%83%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%88operator-precedence%EF%BC%89) - - [语句](#%E8%AF%AD%E5%8F%A5) - - [条件控制语句](#%E6%9D%A1%E4%BB%B6%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5) - - [循环控制语句](#%E5%BE%AA%E7%8E%AF%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5) - - [for-in](#for-in) - - [异常处理语句](#%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E8%AF%AD%E5%8F%A5) - - [with 语句](#with-%E8%AF%AD%E5%8F%A5-1) - - [闭包](#%E9%97%AD%E5%8C%85) - - [闭包的应用](#%E9%97%AD%E5%8C%85%E7%9A%84%E5%BA%94%E7%94%A8) - - [保存变量现场](#%E4%BF%9D%E5%AD%98%E5%8F%98%E9%87%8F%E7%8E%B0%E5%9C%BA) - - [封装](#%E5%B0%81%E8%A3%85) - - [面向对象](#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1) - - - -# JavaScript 程序设计 - -## JavaScript 介绍 - -前端开发三要素,`HTML`(描述网页内容),`CSS`(描述样式),`JavaScript`(控制网页行为)。JavaScript 为解释型编程语言,运行环境也很广泛。 - -![](../img/J/javascript-history.png) - -![](../img/J/javascript-env.png) - -**JavaScript**的引入方法如下: - -```javascript - - - - - - - - - - - - - - - - -``` - -## 调试器 - -调试工具都内置于主流浏览器中(Firefox 中需独立下载 Firebug)。更多关于 Google Chrome DevTools 的信息可以在[这里](https://developer.chrome.com/devtools)找到。 - -## 基本语法 - -### 变量标示符 - -**变量**的命名 - -```javascript -var _name = null; -var $name = null; -var name0 = null; -``` - -### 关键字与保留字 - -JavaScript 在语言定义中保留的字段,这些字段在语言使用中存在特殊意义或功能,在程序编写的过程中不可以当做变量或函数名称使用。无需记忆,报错修改即可。 - -### 字符敏感 - -字符串的大小写是有所区分的,不同字符指代不同的变量。 - -### 严格模式 - -**增益** - -- 消除语法中不合理与不安全的问题,保证代码正常运行 -- 提高编译效率,增加运行速度 - -**使用方法** - -```javascript - -"use strict"; -(function(){ - console.log('>>> Hello, world!'); -})() - - -(function(){ - "use strict"; - console.log('>>> Hello, world!'); -})() -``` - -严格模式与标准模式的区别: - -- 严格模式下隐式声明或定义变量被静止 -- 严格模式下对象重名的属性在严格模式下被静止 -- 严格模式下 `arguments.callee()` 被禁用 -- 严格模式下 `with()` 语句 -- 更多限制 - -### 注释 - -```javascript -/* - 多行注释,不可嵌套 - */ - -// 单行注释 -``` - -## 类型系统 - -![](../img/J/javascript-variable-type.jpg) - -### 标准类型 - -**原始类型**: - -- Undefined -- Null -- Boolean -- String -- Number - -**引用类型**: -- Object - -```javascript -var obj = {}; - -var bool = new Boolean(true); -var str = new String("hello"); -var num = new Number(1); -var obj0 = new Object(); -``` - -原始类型和引用类型的区别: - -原始类型储存在栈(Stack)中储存变量的值,而引用类型在栈中保存的是所引用内容储存在堆(Heap)中的值。类似于指针的概念,引用类型并非储存变量真实数值而是地址,所以对已引用类型的复制其实只是复制了相同的地址而非实际的变量值。 - -**Undefined** 值:undefined 出现场景: - -- 以声明为赋值的变量 `var obj;` -- 获取对象不存在的属性 `var obj = {x: 0}; obj.y;` -- 无返回值函数的执行结果 `function f(){}; var obj = f();` -- 函数参数没有传入 `function f(i){console.log(i)}; f();` -- `void(expression)` - -**Null** 值:null 出现场景: - -- 获取不存在的对象 `document.getElementById('not-exist-element')` - -**Boolean** 值:true, false 出现场景: - -- 条件语句导致的系统执行的隐式类型转换 `if(隐式转换){}` -- 字面量或变量定义 `var bool = true;` - -**String** 值:字符串 出现场景: - -- `var str = 'Hello, world!';` - -**Number** 值:整型直接量,八进制直接量(0-),十六进制直接量(0x-),浮点型直接量 出现场景: - -- `1026` -- `3.14` -- `1.2e5` -- `0x10` - -**Object** 值:属性集合 出现场景: - -- `var obj = {name: 'Xinyang'};` - -### 变量转换表 - -|Value|Boolean|Number|String| -|-----|-------|------|------| -|undefined|false|NaN|"undefined"| -|null|false|0|"null"| -|true|true|1|"true"| -|false|false|0|"false"| -|''|false|0|''| -|'123'|true|123|'123'| -|'1a'|true|NaN|'1a'| -|0|false|0|"0"| -|1|true|1|"1"| -|Infinity|true|Infinity|"Infinity"| -|NaN|false|NaN|'NaN'| -|{}|true|NaN|"[object Object]"| - -### 类型识别 - -- `typeof` -- `Object.prototype.toString` -- `constructor` -- `instanceof` - -**typeof**: -- 可以是标准类型(Null 除外) -- 不可识别具体的对象类型(Function 除外) - -**Object.prototype.toString**: -- 可是识别标准类型及内置对象类型(例如,Object, Date, Array) -- 不能识别自定义对象类型 - -**constructor**: -- 可以识别标准类型(Undefined/Null 除外) -- 可识别内置对象类型 -- 可识别自定义对象类型 - -```javascript -function getConstructiorName(obj) { - return obj && obj.constructor && obj.constructor.toString().match(/function\s*([^(]*)/)[1]; -} -getConstructiorName([]) === "Array"; // true -``` - -**instanceof**: -- 不可判别原始类型 -- 可判别内置对象类型 -- 可判别自定义对象类型 - -## 内置对象 - -通常情况下只有对象才存在方法,但 JavaScript 不同它具有12种内置对象。内置对象又分为两类,普通对象(属性和方法)与构造器对象(可用于实例化普通对象,它还包含原型对象属性和方法,及实例对象属性和方法)。 - -**JavaScript 对象原型链的简要说明** - -``` -function Point(x, y) { - this.x = x; - this.y = y; -} -Point.prototype.move = function(x, y) { - this.x += x; - this.y += y; -} -var p = new Point(1, 1); -p.move(2,2); -``` - -`__proto__` 称之为原型链,有如下特点: - -1. `__proto__` 为对象内部的隐藏属性 -1. `__proto__` 为实例化该对象的构造器的 `prototype` 对象的引用,因此可以直接方法 `prototype` 的所有属性和方法 -1. 除了 `Object` 每个对象都有一个 `__proto__` 属性且逐级增长形成一个链,原型链顶端是一个 `Object` 对象。 -1. 在调用属性或方法时,引擎会查找自身的属性如果没有则会继续沿着原型链逐级向上查找,直到找到该方法并调用。 -1. `__proto__` 跟浏览器引擎实现相关,不同的引擎中名字和实现不尽相同(chrome、firefox中名称是 `__proto__` ,并且可以被访问到,IE中无法访问)。基于代码兼容性、可读性等方面的考虑,不建议开发者显式访问 `__proto__` 属性或通过 `__proto__`更改原型链上的属性和方法,可以通过更改构造器` prototype` 对象来更改对象的 `__proto__` 属性。 - -**构造器对象与普通对象的区别** - -![](../img/O/object-with-constructor-and-regular-object.png) - -1. 构造器对象原型链中的 `__proto__` 是一个 `Function.prototype` 对象的引用,因此可以调用 `Function.prototype`的属性及方法 -1. 构造器对象本身有一个 `prototype` 属性,用该构造器实例化对象时该 `prototype` 会被实例对象的 `__proto__` 所引用 -1. 构造器对象本身是一个 `function` 对象,因此也会有自身属性 - -### 标准内置对象 - -**构造器对象** - -- Object -- Boolean -- String -- Number -- Function -- Array -- RegExp -- Date -- Error - -**其他对象** - -- Math -- JSON -- 全局对象 - -### Object - -> 构造器的原型对象在对象实例化时将会被添加到实例对象的原型链当中。 -> `__proto__` 为原型链属性,编码时不可被显像调用。但是实例化对象可以调用原型链上的方法。 - -用 String/Number 等构造器创建的对象原型链顶端对象始终是一个Object对象,因此这些对象可以调用Object的原型对象属性和方法。所以 String/Number 等构造器是 Object 的子类。 - -更多关于 Object 的内容可以在[这里](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)找到。 - -**构造器说明**: -- Object 是属性和方法的集合 -- String/Number/Boolean/Array/Date/Error 构造器均为 Object 的子类并集成 Object 原型对象的属性及方法。 - -**实例化方法** -``` -var obj0 = new Object({name: 'X', age: 13}); -// 常用方法 -var obj1 = {name: 'Q', age: 14}; -``` - -**属性及方法** -- prototype -- create -- keys -- ... - -**原型对象属性及其方法 -- constructor -- toString -- valueOf -- hasOwnProperty -- ... - -**实例对象属性及方法** - -无 - -#### Object.create - -功能:基于原型对象创造新对象 - -```javascript -// Object.create(prototype[, propertiesObject]) -var prototype = {name: 'X', age: 13}; -var obj = Object.create(proto); -``` - -#### Object.prototype.toString - -功能:获取方法调用者的标准类型 - -```javascript -// objectInstance.toString() -var obj = {}; -obj.toString(); // Object -``` - -#### Object.prototype.hasOwnProperty - -功能:判断一个属性是否是一个对象的自身属性 - -```javascript -// objectInstance.hasOwnProperty("propertyName") -var obj = Object.create({a: 1, b: 2}); -obj.c = 3; -obj.hasOwnProperty('a'); // false -obj.hasOwnProperty('c'); // true -``` - -### Boolean - -**构造器说明**:值为 true 与 false - -**属性及方法** -- prototype - -**原型对象属性及其方法 -- constructor, toString, valueOf - -### String - -**构造器说明**:单双引号内的字符串 - -**实例化方法** -```javascript -'Hello, world!' -var str0 = 'Xinyang'; -var str1 = new String('Xinyang'); -``` - -**属性及方法** -- prototype -- fromCharCode(转换 ASCII 代码为字符) - -**原型对象属性及其方法** -- constructor -- indexOf -- replace -- slice -- split -- charCodeAt -- toLowerCase -- ... - -#### String.prototype.indexOf - -功能:获取子字符串在字符串中的索引 - -```javascript -// stringObject.indexOf(searchValue, fromIndex) -var str = "I am X. From China!"; -var index = str.indexOf('a'); // 2 -str.indexOf('a', index + 1); // 16 -str.indexOf('Stupid'); // -1 字符串不存在 -``` - -#### String.prototype.replace - -功能:查找字符串替换成目标文字 - -```javascript -// stringObject.replace(regexp/substr, replacement) -var str = "apple is bad"; -str = str.replace('bad', 'awesome'); -``` - -#### String.prototype.split - -功能:按分隔符将分隔符分成字符串数组 - -```javascript -// stringObject.split(separator, arrayLength) -var str = '1 2 3 4'; -str.split(' '); // ['1', '2', '3', '4']; -str.split(' ', 3); // ['1', '2', '3']; -str.split(/\d+/); // ["", " ", " ", " ", ""] -``` - -### Number - -**构造器说明**:整型直接量,八进制直接量(0-),十六进制直接量(0x-),浮点型直接量 - -**实例化方法** - -```javascript -10 -1.2e5 -var count = 0x10; -var pi = new Number(3.1415); -``` - -**属性及方法** -- prototype -- MAX_VALUE -- MIN_VALUE -- NaN -- NEGATIVE_INFINITY -- POSITIVE_INFINITY - -**原型对象属性及其方法** -- constructor -- toFixed -- toExponential -- ... - -#### Number.prototype.toFixed - -功能:四舍五入至指定小数位 - -```javascript -// numberObject.toFixed(num) -var num0 = 3.14; -num0.toFixed(1); // 3.1 -var num1 = 3.35; -num1.toFixed(1); // 3.4 -``` - -### Array - -**构造器说明**:定义数组对象 - -**实例化方法** - -```javascript -var a0 = [1, 'abc', true, function(){}]; -var a1 = new Array(); -var a2 = new Array(1, 'abc', true); -``` - -**属性及方法** -- prototype -- isArray - -**原型对象属性及其方法** -- constructor -- splice -- forEach -- find -- concat -- pop -- push -- reverse -- shift -- slice -- ... - -#### Array.prototype.splice - -功能:从数组中删除或添加元素,返回被删除的元素列表(作用域原有数组) - -```javascript -// arrayObject.splice(start, deleteCount[, item1[, item2[, ...]]]) -var arr = ['1', '2', 'a', 'b', '6']; -var ret = arr.splice(2, 2, '3', '4', '5'); // ['a', 'b'] -arr; // ['1', '2', '3', '4', 5', '6'] -``` - -#### Array.prototype.forEach - -功能:遍历元素组并调用回调函数 - -```javascript -// arrayObject.forEach(callback[, thisArg]) -// 回调函数 -// function callback(value, index, arrayObject) {...} -// value - 当前值 index - 当前索引 arrayObject - 数组本身 -function logArray(value, index, arrayObject) { - console.log(value); - console.log(value === array[index]); -} -[2, 5, , 9].forEach(logArray); -``` - -### Function - -**构造器说明**:定义函数或新增对象构造器 - -**实例化方法** - -```javascript -// 对象实例化 -var f0 = new Function('i', 'j', 'return (i + j)'); -// 函数关键字语句 -function f1(i, j){return i + j;} -// 函数表达式 -var f3 = function(i, j){return i + j;}; -``` - -**属性及方法** -- prototype - -**原型对象属性及其方法** -- constructor -- apply -- call -- bind - -**实例对象属性和方法** -- length -- prototype -- arguments -- caller - -#### 自定义对象构造器 - -```javascript -function Point(x, y) { - this.x = x; - this.y = y; -} - -Point.prototype.move = function(x, y) { - this.x += x; - this.y += y; -} - -var p = new Point(1, 2); -``` - -#### Function.prototype.apply - -功能:通过参数指定调用者和函数参数并执行该函数 - -```javascript -// functionObj.apply(thisArg[, argsArray]) -function Point(x, y) { - this.x = x; - this.y = y; -} - -Point.prototype.move = function(x, y) { - this.x += x; - this.y += y; -} - -var p = new Point(1, 1); -var circle = {x: 1, y: 1, r: 1}; -p.move.apply(circle, [2, 1]); // {x: 3, y: 2, r: 1} -``` - -#### Function.prototype.bind - -功能:通过参数指定函数调用者和函数参数并返回该函数的引用 - -```javascript -// functionObj.bind(thisArg[, arg1[, arg2[, ...]]]) -function Point(x, y) { - this.x = x; - this.y = y; -} - -Point.prototype.move = function(x, y) { - this.x += x; - this.y += y; -} - -var p = new Point(1, 1); -var circle = {x: 1, y: 1, r: 1}; -var circleMoveRef = p.move.bind(circle, 2, 1); -setTimeout(circleMoveRef, 1000); // {x: 3, y: 2, r: 1} - -// 之间使用 circleMoveRef() 效果等同于 apply() -circleMoveRef(); -``` - -#### 子类构造器 - -```javascript -function Circle(x, y, r) { - Point.apply(this, [x, y]); - this.radius = r; -} -Circle.prototype = Object.create(Point.prototype); -Circle.prototype.constructor = Circle; -Circle.prototype.area = function(){ - return Math.PI * this.radius * this.radius; -} - -var c = new Circle(1, 2, 3); -c.move(2, 2); -c.area(); -``` - -#### 函数调用 - -- `()` -- `apply` -- `call` - -#### 函数参数 - -- 形参个数不一定等于实参个数 -- 值专递 -- 通过参数类型检查实现函数重载 - -##### arguments - -arguments 的常用属性 -- length 实参个数 -- 0...arguments.length-1 实参属性名称(key) -- callee 函数本身 - -```javascript -function max(a, b) { - if (max.length === arguments.length) { - return a>b?a:b; - } else { - var _max = arguments[0]; - for(var i = 0; i < arguments.length; i++) { - if (_max < arguments[i]) { - _max = arguments[i]; - } - } - return _max; - } -} -``` - -##### 值专递 - -函数参数的值专递是参数复制都是栈内存中的复制。 - -![](../img/M/memory-management.jpg) - -```javascript -// 原始类型 -function plusplus(num) { - return num++; -} -var count = 0; -var result = plusplus(count); // result = 1; count = 0; - -// 引用类型 -function setName(obj) { - obj.name = 'obama'; -} -var president = {name: 'bush'}; -setName(president); // {name: 'obama'}; -``` - -##### 函数重载 - -以 `Require.JS` 中的 `define()` 为例: - -```javascript -define(function(){ - var add = function(x, y) { - return x + y; - }; - return { - add: add - }; -}) - -define(['lib'], function(){ - var add = function(x, y) { - return x + y; - }; - return { - add: add - }; -}) - -define('math', ['lib'], function(){ - var add = function(x, y) { - return x + y; - }; - return { - add: add - }; -}) - -// define 的实现代码 -/** - * The function that handles definitions of modules. Differs from - * require() in that a string for the module should be the first argument, - * and the function to execute after dependencies are loaded should - * return a value to define the module corresponding to the first argument's - * name. - */ -define = function (name, deps, callback) { - var node, context; - - //Allow for anonymous modules - if (typeof name !== 'string') { - //Adjust args appropriately - callback = deps; - deps = name; - name = null; - } - - //This module may not have dependencies - if (!isArray(deps)) { - callback = deps; - deps = null; - } - - // 省略以下代码 - // ... -}; -``` - -### RegExp - -**构造器说明**:用于定义正则表达式,一个 RegExp 对象包含一个正则表达式和关联的标志 - -**定义方法** -- `/pattern/flags` -- `new RegExp(pattern[, flags]);` - -**属性及方法** -- prototype - -**原型对象属性及其方法** -- constructor -- test -- exec -- ... - -#### RegExp.prototype.test - -功能:使用正则表达式对字符串进行测试,并返回测试结果 - -```javascript -// regexObj.text(str) -var reg = /^abc/i; -reg.test('Abc123'); // true -reg.test('1Abc1234'); // false -``` - -### Date - -**构造器说明**:用于定义日期对象 - -**定义方法** -```javascript -var date0 = new Date(); -var date1 = new Date(2014, 3, 1, 7, 1, 1, 100); -``` - -**属性及方法** -- prototype -- parse -- now -- ... - -**原型对象属性及其方法** -- constructor -- Date -- getDate -- getHours -- setDate -- setHours -- ... - -### 标准内置对象 - -#### Math - -**对象说明**:拥有属性和方法的单一对象主要用于数字计算 - -**对象属性**: -- E -- PI -- SQRT2 -- ... - -**对象方法**: -- floor -- random -- abs -- max -- cos -- ceil - -##### Math.floor - -功能:向下取整 - -```javascript -// Math.floor(num) -Math.floor(0.97); // 0 -Math.floor(5.1); // 5 -Math.floor(-5.1); //6 -``` - -相似方法:`ceil`,`round` - -##### Math.random - -功能:返回 0~1 之间的浮点数 - -```javascript -// Math.random() -Math.random(); // 0.14523562323461 -``` - -#### JSON - -**对象说明**:用于存储和交换文本信息 - -**对象方法**: -- parse -- stringify - -##### JSON.stringify - -功能:将 JSON 对象转换为字符转 - -```javascript -// JSON.stringify(value[, replacer[, space]]) -var json = {'name': 'X'}; -JSON.stringify(json); // "{"name":"X"}" -``` - -##### JSON.parse - -功能:将 JSON 字符转转换为对象 - -``` -// JSON.parse(text[, reviver]) -var jsonStr = '{"name":"X"}'; -JSON.parse(jsonStr); // {name: 'X'} -``` - -#### 全局对象 - -全局对象定义了一系列的属性和方法在编程过程中可以被之间调用。 - -属性:NaN,Infinity,undefined - -方法: -- parseInt -- parseFloat -- isNaN -- isFinite -- eval - -处理 URI 方法: -- encodedURIComponent -- decodeURIComponent -- encodedURI -- decodeURI - -构造器属性: -- Boolean -- String -- Number -- Object -- Function -- Array -- Date -- Error -- ... - -对象属性: -- Math -- JSON - -##### NaA - -非数字值:表示错误或无意义的运算结果,NaN 参与运算仍会返回 NaA,且 NaN 不等于任何值,包括它本身。可以使用 `isNaN()` 判断运算结果的类型是否为 NaN。 - -```javascript -isNaN(NaN); // true -isNaN(4 - '2a'); // true; -``` - -##### parseInt - -功能:转换字符串成数字 - -```javascript -// parseInt(string[, radix]) -// radix - 为进制数 -parseInt('010'); // 10 -parseInt('010', 8) // 8 -parseInt('010', 16) // 16 - -parseInt('0x1f'); // 31 -parseInt('0x1f', 16); // 31 -parseInt('1f'); // 1 -parseInt('1f', 16); // 31 -``` - -##### eval - -功能:计算字符串并执行其中的 JavaScript 代码(会带来安全性和代码逻辑问题,通常不建议使用) - -```javascript -// eval(string) -var res = '{"error": "0", "msg": "OK"}; -var obj; -if (!JSON) { - obj = eval('(' + res + ')'); -} else { - obj = JSON.parse(res); -} -``` - -##### encodedURIComponent - -功能:将 URI 参数中的特殊字符,中文等作为 URI 的一部分进行编码 - -```javascript -var uri = "http://w3schools.com/my test.asp?name=ståle&car=saab"; -var res = encodeURIComponent(uri); - -// 结果 -// http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab -``` - -## 变量作用域 - -变量的作用域值的是变量的生命周期和作用范围(全局与局部作用域的区别)。 - -### 作用域介绍 - -#### 静态作用域 - -静态作用域有称为词法作用域,即指其在编译的阶段就可以决定变量的引用。**静态作用域**只更变量定义的位置有关与代码执行的顺序无关。 - -```javascript -var x = 0; -function foo() { - alert(x); -} - -function bar() { - var x = 20; - foo(); -} - -foo(); -``` - -![](../img/S/scope-lexical-scope.png) - -#### 动态作用域 - -动态作用域的变量引用只可在程序运行时刻决定(其通常通过动态栈来进行管理)。 - -```javascript -var x = 0; -function foo() { - alert(x); -} - -function bar() { - var x = 20; - foo(); -} - -foo(); -``` - -![](../img/S/scope-dynamic-scope.gif) - -### JavaScript 变量作用域 - -JavaScript (1)使用静态作用域,(2)其没有块级作用域(只有函数作用域,就是只有 function 用于可以定义作用域),(3)在 ES5 之作使用词法环境来管理作用域。 - -#### 词法环境 - -##### 组成 - -用来描述静态作用域的数据结构。 - -- 环境记录(record)(指形参,变量,函数等) -- 外部词法环境的引用(outer) - -##### 创建 - -在一段代码执行之前,先初始化词法环境。会被初始化的有: - -- 形参 -- 函数定义(创建函数对象,会保存当前作用域。见下图) -- 变量定义(所有初始化值均为 `undefined`) - -![](../img/S/scope-function-init.png) - -##### 结构 - -```javascript -var x = 10; -function foo(y) { - var z = 30; - function bar(q) { - return x + y + z + q; - } - return bar; -} -var bar = foo(20); -bar(40); -``` - -**全局词法作用域(初始化状态)** - -![](../img/S/scope-global-init.png) - -**函数词法作用域** - -![](../img/S/scope-structure.jpg) - -#### 关于词法环境的问题 - -**命名冲突** - -形参,函数定义,变量名称命名冲突。其中的优先级的排序如下: - -``` -函数定义 > 形参 > 变量 -``` - -**`arguments` 的使用** - - 为函数中定义好的变量。 - -**函数表达式与函数定义的区别** - -- 函数表达式是在执行时才创建函数对象。 -- 函数定义为在代码执行之前就进行创建的。 - -#### with 语句 - -`with` 会创造一个临时作用域。 - -```javascript -var foo = 'abc'; -with({ - foo: 'bar'; -}) { - function f() { - alert(foo); - }; - (function() { - alert(foo); - })(); - f(); -} -``` - -#### try-catch 句法 - -``` -try { - var e = 10; - throw new Error(); -} catch (e) { - function f() { - alert(e); - } - (function() { - alert(e); - })(); - f(); -} -``` - -#### 带名称的函数表达式 - -**下面例子为不常规的写法** - -``` -(function A(){ - A = 1; - alert(A); -})(); -``` - -![](../img/S/scope-function-with-name.png) - -## 表达式与运算符 - -### 表达式 - -表达式为 JavaScript 的短语可执行并生成值。 - -```javascript -1.7 // 字面量 -"1.7" -var a = 1; -var b = '2'; -var c = (1.7 + a) * '3' - b -``` - -### 运算符 - -- 算数运算符 (`+` `-` `*` `/` `%`) -- 关系运算符 (`>` `<` `==` `!=` `>=` `<=` `===` `!==`) -- 逻辑运算符 (`!` `&&` `||`) -- 位运算符 (`&` `|` `^` `~` `<<` `>>`) -- 负值运算符 (`=`) -- 条件运算符 (`?:`) -- 逗号运算符 (`,`) -- 对象运算符 (`new` `delete` `.` `[]` `instanceof`) - -#### === - -全等运算符用于盘对左右两边的对象或值是否类型相同且值相等。 - -**伪代码拆解** - -```javascript -function totalEqual(a, b) { - if (a 和 b 类型相同) { - if (a 和 b 是引用类型) { - if (a 和 b 是同一引用) - return true; - else - return false; - } else { // 值类型 - if (a 和 b 值相等) - return true; - else - return false; - } - } else { - return false; - } -} -``` - -**例子** - -```javascript -var a = "123"; -var b = "123"; -var c = "4"; -var aObj = new String("123"); -var bObj = new String("123"); -var cObj = aObj; - -a === aObj // false -aObj === bObj // false -aObj === cObj // true -a === b // true -a === c // false -``` - -#### == - -`==` 用于判断操作符两边的对象或值是否相等。 - -**伪代码拆解** - -```javascript -function equal(a, b) { - if (a 和 b 类型相同) { - return a === b; - } else { // 类型不同 - return Number(a) === Number(b); // 优先转换数值类型 - } -} -``` - -**例子** - -```javascript -"99" == 99; // true -new String("99") == 99; // true -true == 1; // true -false == 0; // true -'\n\n\n' == // true -``` - -##### 例外规则 - -- `null == undefined` 结果为真 `true` -- 在有 `null`/`undefined` 参与的 `==` 运算是不进行隐式转换。 - -```javascript -0 == null; // false -null == false; // false -"undefined" == undefined; // false -``` - -#### ! - -`!x` 用于表达 x 表达式的运行结果转换成布尔值(Boolean)之后取反的结果。`!!x` 则表示取 x 表达式的运行结果的布尔值。 - -```javascript -var obj = {}; -var a = !obj // false; -var a = !!obj // true; -``` - -#### && - -`x && y` 如果 x 表达式的运行交过转换成 Boolean 值为 false 则不运行表达式 y 而直接返回 x 表达式的运行结果。**相反**,如果 x 表达式的运行交过转换成 Boolean 值为 true 则运行表达式 y 并返回 y 表达式的运行结果。 - -**伪代码拆解** - -```javascript -var ret = null; -if (!!(ret = x)) { - return y; -} else { - return ret; -} -``` - -**例子** - -```javascript -var a = 0 && (function(){return 1 + 1;})(); // 0 -var b = 1 && (function(){return 1 + 1;})(); // 2 -``` - -#### || - -`x || y` 如果 x 表达式的运行结果转换为 Boolean 值为 true,则不运行 表达式 y 而直接返回表达式 x 的运算结果。(与 `&&` 方式相反) - -**伪代码拆解** - -```javascript -var ret = null; -if (!!(ret = x)) { - return ret; -} else { - return y; -} -``` - -**例子** - -```javascript -var a = 0 || (function(){return 1 + 1;})(); // 2 -var b = 1 || (function(){return 1 + 1;})(); // 1 -``` - -### 元算符优先级(Operator Precedence) - -- `+` `-` `*` `/` 高于 `&&` -- `*` `/` 高于 `+` `-` -- `&&` 高于 `?:` -- `()` 内优先级高于之外 - -NOTE:和数学上的算术优先级类似,同级从**左到右**计算。如有疑问加上 `()` 既可解决优先级问题。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PrecedenceOperator typeAssociativityIndividual operators
19Groupingn/a( … )
18Member Accessleft-to-right… . …
Computed Member Accessleft-to-right… [ … ]
new (with argument list)n/anew … ( … )
17Function Callleft-to-right… ( … )
new (without argument list)right-to-leftnew …
16Postfix Incrementn/a… ++
Postfix Decrementn/a… --
15Logical NOTright-to-left! …
Bitwise NOTright-to-left~ …
Unary Plusright-to-left+ …
Unary Negationright-to-left- …
Prefix Incrementright-to-left++ …
Prefix Decrementright-to-left-- …
typeofright-to-lefttypeof …
voidright-to-leftvoid …
deleteright-to-leftdelete …
14Multiplicationleft-to-right… * …
Divisionleft-to-right… / …
Remainderleft-to-right… % …
13Additionleft-to-right… + …
Subtractionleft-to-right… - …
12Bitwise Left Shiftleft-to-right… << …
Bitwise Right Shiftleft-to-right… >> …
Bitwise Unsigned Right Shiftleft-to-right… >>> …
11Less Thanleft-to-right… < …
Less Than Or Equalleft-to-right… <= …
Greater Thanleft-to-right… > …
Greater Than Or Equalleft-to-right… >= …
inleft-to-right… in …
instanceofleft-to-right… instanceof …
10Equalityleft-to-right… == …
Inequalityleft-to-right… != …
Strict Equalityleft-to-right… === …
Strict Inequalityleft-to-right… !== …
9Bitwise ANDleft-to-right… & …
8Bitwise XORleft-to-right… ^ …
7Bitwise ORleft-to-right… | …
6Logical ANDleft-to-right… && …
5Logical ORleft-to-right… || …
4Conditionalright-to-left… ? … : …
3Assignmentright-to-left… = …
… += …
… -= …
… *= …
… /= …
… %= …
… <<= …
… >>= …
… >>>= …
… &= …
… ^= …
… |= …
2yieldright-to-leftyield …
1Spreadn/a... …
0Comma / Sequenceleft-to-right… , …
- -## 语句 - -### 条件控制语句 - -```javascript -if (expression) {statement} -else if (expression) {statement1} -else {statement2} - -// JavaScript 中的 case 可以使用整型,字符串,甚至表达式 -switch(persion.type) { - case "teacher": - statement1 - break; - case "student": - statement2 - break; - default: - statement3 - break; -} -``` - -### 循环控制语句 - -```javascript -while(expression) {statement} - -// 至少执行一次 -do {statement} while(expression); - -for (initialise; test_expresiion; increment) {statement} - -// 跳过下面代码并进入下一轮循环 -continue; - -// 退出当前循环 -break; -``` - -#### for-in - -用于遍历对象的**全部**属性。 - -```javascript -function Car(id, type, color) { - this.type = type; - this.color = color; - this.id = id; -} - -var benz = new Car('benz', 'black', 'red'); -Car.prototype.start = function(){ - console.log(this.type + ' start'); -} - -for (var key in benz) { - console.log(key + ':' benz[key]); -} - -// 输出结果 -type:black -color:red -id:benz -start:function (){ - console.log(this.type + ' start'); -} - -// ----------- - -// 如不需原型对象上的属性可以使用 hasOwnProperty -for (var key in benz) { - if (benz.hasOwnProperty(key)) { - console.log(key + ':' benz[key]); - } -} - -// 输出结果 -type:black -color:red -id:benz -``` - -### 异常处理语句 - -```javascript -try/catch/finally -throw -``` - -### with 语句 - -`with` 语句是 JavaScript 中特有的语句形式,其用于缩短特定情况下必须书写的代码量。它可以暂时改变变量的作用域,将`with`语句中的对象添加至作用域链的头部。**缺点**就是导致 JavaScript 语句的可执行性下降,所以通常情况下因尽可能的避免使用。 - -```javascript -// 使用 with 之前 -(function(){ - var x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10); - var y = Math.tan(14 * Math.E); -})(); - -// 使用 with -(function(){ - with(Math) { - var x = cos(3 * PI) + sin(LN10); - var y = tan(14 * E); - } -})(); -``` - -![](../img/W/with-scope.png) - -```javascript -frame[1].document.forms[0].name.value = ""; -frame[1].document.forms[0].address.value = ""; -frame[1].document.forms[0].email.value = ""; - -with(frame[1].document.[0]) { - name.value = ""; - address.value = "" - email.value = ""; -} - -``` - -## 闭包 - -- 闭包有函数和与其相关的引用环境的组合而成 -- 闭包允许函数访问其引用环境中的变量(又称自由变量) -- 广义上来说,所有 JavaScript 的函数都可以成为闭包,因为 JavaScript 函数在创建时保存了当前的词法环境。 - -``` -function add() { - var i = 0; - return function() { - alert(i++); - } -} -var f = add(); -f(); -f(); -``` - -### 闭包的应用 - -#### 保存变量现场 - -```javascript - -// 错误方法 -var addHandlers = function(nodes) { - for (var i = 0, len = nodes.length; i < len; i++) { - nodes[i].onclick = function(){ - alert(i); - } - } -} - -// 正确方法 -var addHandlers = function(nodes) { - var helper = function(i) { - return function() { - alert(i); - } - } - - var (var i = 0, len = nodes.length; i < len; i++) { - nodes[i].onclick = helper(i); - } -} -``` - -#### 封装 - -```javascript - -// 将 observerList 封装在 observer 中 -var observer = (function(){ - var observerList = []; - return { - add: function(obj) { - observerList.push(obj); - }, - empty: function() { - observerList = []; - }, - getCount: function() { - return observerList.length; - }, - get: function() { - return observerList; - } - }; -})(); -``` - -## 面向对象 - -Creative Commons License
This work by Li Xinyang is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. \ No newline at end of file diff --git a/Progress.md b/Progress.md deleted file mode 100644 index c3b019b..0000000 --- a/Progress.md +++ /dev/null @@ -1,84 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [Javascript程序设计 20/23](#javascript%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1-2023) -- [页面制作 39/41](#%E9%A1%B5%E9%9D%A2%E5%88%B6%E4%BD%9C-3941) - - - -# Javascript程序设计 20/23 - -|章节|课题|状态|时间戳| -|----|----|----|------| -|JS介绍|JS介绍|★|1505272223| -|调试器|调试器|★|1505272223| -|基本语法|基本语法|★|1505272223| -|类型系统|基本类型|★|1505272223| -|类型系统|类型识别|★|1505281609| -|内置对象|简介|★|1505292247| -|内置对象|Object|★|1505292247| -|内置对象|String|★|1505292248| -|内置对象|Number|★|1505292248| -|内置对象|Boolean|★|1505312132| -|内置对象|String, Number, Boolean|★|1505312132| -|内置对象|Array|★|1505312132| -|内置对象|Function|★|1505312132| -|内置对象|RegExp, Date, Error|★|1505312132| -|内置对象|Math, JSON|★|1505312132| -|内置对象|全局对象|★|1505312132| -|表达式, 运算符|表达式, 运算符|★|1506091507| -|语句|语句|★|1506091507| -|变量作用域|变量作用域|★|150738| -|闭包|闭包|★|1506091529| -|面向对象|简介||| -|面向对象|原型||| -|面向对象|JS面向对象||| - -# 页面制作 39/41 - -|章节|课题|状态|时间戳| -|----|----|----|------| -|Photoshop|工具, 面板, 视图|★|1505251953| -|Photoshop|测量, 取色|★|1505251953| -|Photoshop|切图|★| 1505252051| -|Photoshop|保存|★| 1505262108| -|Photoshop|修改维护|★| 1505262117| -|Photoshop|图片优化与合并|★|1505262225| -|开发调试|开发工具|★| 1505251248| -|开发调试|调试工具|★| 1505251248| -|HTML|概念|★|1505262243| -|HTML|HTML 文档|★|1505262243| -|HTML|语法|★|1505262243| -|HTML|章节标签|★|1505271407| -|HTML|文本标签|★|1505271428| -|HTML|组标签|★|1505271435| -|HTML|资源标签|★|1505272024| -|HTML|表格标签|★|1505272025| -|HTML|表单标签|★|1505272025| -|HTML|语义化|★|1505272032| -|HTML|实体字符|★|1505272033| -|CSS|简介|★|1505312302| -|CSS|语法|★|1506011814| -|CSS|简单选择器|★|1506011814| -|CSS|其他选择器|★|1506011814| -|CSS|继承, 优先, 层级|★|1506011814| -|CSS|字体|★|1506011856| -|CSS|对齐方式|★|1506012147| -|CSS|格式处理|★|1506031421| -|CSS|文本修饰|★|1506031435| -|CSS|高级选项|★|1506031436| -|CSS|盒子模型 I|★|1506031530| -|CSS|盒子模型 II|★|1506031531| -|CSS|背景 I|★|1506042223| -|CSS|背景 II|★|1506042223| -|CSS|布局 display|★|1506051313| -|CSS|布局 position|★|1506051313| -|CSS|布局 float|★|1506051723 -|CSS|布局 flex|★|1506062334| -|CSS|变形 2D|★|1506071407| -|CSS|变形 3D|★|1506071407| -|CSS|动画 transition|★|1506071626| -|CSS|动画 animation|★|1506071626| - -Creative Commons License
This work by Li Xinyang is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. \ No newline at end of file diff --git a/README.md b/README.md index c7d41c7..1ad96d2 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,63 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* +# 前端开发笔记本 -- [知识体系内容记录](#%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB%E5%86%85%E5%AE%B9%E8%AE%B0%E5%BD%95) - - [Javascript 程序设计](#javascript-%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1) - - [页面制作](#%E9%A1%B5%E9%9D%A2%E5%88%B6%E4%BD%9C) - - [DOM 编程](#dom-%E7%BC%96%E7%A8%8B) - - [页面架构](#%E9%A1%B5%E9%9D%A2%E6%9E%B6%E6%9E%84) - - [产品前端架构](#%E4%BA%A7%E5%93%81%E5%89%8D%E7%AB%AF%E6%9E%B6%E6%9E%84) -- [相关资源](#%E7%9B%B8%E5%85%B3%E8%B5%84%E6%BA%90) -- [相关链接](#%E7%9B%B8%E5%85%B3%E9%93%BE%E6%8E%A5) +[![Join the chat at https://gitter.im/li-xinyang/FEND_Note](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/li-xinyang/FEND_Note?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - +点击[这里](https://www.gitbook.com/read/book/li-xinyang/frontend-notebook)开始在 GitBook 阅读! -## 知识体系内容记录 +点击[这里](http://wiki.jikexueyuan.com/project/fend_note/)开始在极客学院 Wiki 阅读!(中国大陆访问速度较快) -![](img/C/career-path.jpg) +前端开发笔记本的 GitHub 项目地址在[这里](https://github.com/li-xinyang/FEND_Note)。如果你觉得这个项目不错,请点击 **Star** 一下,您的支持是我最大的动力。 -### Javascript 程序设计 + -![](http://progressed.io/bar/87?title=Progress) [详情](JavascriptDesignPattern/JavascriptDesignPattern.md) +Star -### 页面制作 +  Watch -![](http://progressed.io/bar/100?title=Progress) [详情](WebCreation/WebCreation.md) +  Fork -### DOM 编程 +  Download -![](http://progressed.io/bar/0?title=Progress) [详情](#) +![笔记路径规划](img/C/career-path.jpg) -### 页面架构 +《前端笔记本》涵盖了 Web 前端开发所需的全部基本知识以及所对应的学习路径。它并不能当做一本完整的学习材料来进行前端的学习,因为在有限的篇幅中无法深入的展开每一个单独的知识点。它更适合作为一个学习清单或者是查询手册,结合其他在各个方面更专业的图书或者官方文档来进行同步学习。在学习过程中为了能达到最佳的学习效果,也可将每个技术点实现并进行适当的拓展。 -![](http://progressed.io/bar/0?title=Progress) [详情](#) +### 写作进程 -### 产品前端架构 +*第一版草稿* 完成时间 1507252244 -![](http://progressed.io/bar/0?title=Progress) [详情](#) +| 章节 | 名称 | 进程 | +| :--- | :-------------- | :-------------------------------- | +| 第一章 | 页面制作 | ![](http://progressed.io/bar/100) | +| 第二章 | JavaScript 程序设计 | ![](http://progressed.io/bar/100) | +| 第三章 | DOM 编程 | ![](http://progressed.io/bar/100) | +| 第四章 | 页面构架 | ![](http://progressed.io/bar/100) | +| 第五章 | 前端产品构架 | ![](http://progressed.io/bar/100) | -## 相关资源 +### 成就 -- [书单](Booklist.md) +**1508311803** - 100 Stars: [@dszls](https://github.com/dszls), thank you! -## 相关链接 +**1511071358** - 200 Stars: [@cschenchen](https://github.com/cschenchen) + +**1511222144** - 300 Stars: [@lujun9972](https://github.com/lujun9972) + +**1512102333** - 400 Stars: [@Niefee](https://github.com/Niefee) + +**1601231619** - 500 Stars: [@wangdsh](https://github.com/wangdsh) + +**1603261510** - 600 Stars: [@lty2226262](https://github.com/lty2226262) + +### 相关链接 - [NEC](http://nec.netease.com/) {N: nice, E: easy, C: css;} -Creative Commons License
This work by Li Xinyang is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. \ No newline at end of file +### 声明 + +前端笔记本大纲及内容由[网易云课堂前端专业](http://mooc.study.163.com/smartSpec/detail/12001.htm_)改编 + +Creative Commons License
This work by Li Xinyang is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + + + + diff --git a/SUMMARY.md b/SUMMARY.md new file mode 100644 index 0000000..dbfaee6 --- /dev/null +++ b/SUMMARY.md @@ -0,0 +1,68 @@ +# Summary + +- [页面制作](chapter1/00_intro.md) + - [Photoshop](chapter1/01_photoshop.md) + - [工具、面板、视图](chapter1/01_01_tool_panel_view.md) + - [测量及取色](chapter1/01_02_measurement_and_color.md) + - [切图](chapter1/01_03_slice.md) + - [图片保存](chapter1/01_04_save_image.md) + - [图片优化与合并](chapter1/01_05_image_optimisation.md) + - [开发及调试工具](chapter1/02_dev_tools.md) + - [Sublime 编辑器](chapter1/02_01_sublime.md) + - [Atom 编辑器](chapter1/02_02_atom.md) + - [HTML](chapter1/03_html.md) + - [HTML 简介](chapter1/03_01_html_intro.md) + - [HTML 语法](chapter1/03_02_html_sytax.md) + - [HTML 标签](chapter1/03_05_html_tags.md) + - [实体字符](chapter1/03_03_html_ascii_encoding.md) + - [浏览器兼容](chapter1/03_04_cross_browser.md) + - [CSS](chapter1/04_css_intro.md) + - [语法](chapter1/04_01_css_sytax.md) + - [选择器](chapter1/04_02_selector.md) + - [文本](chapter1/04_03_text.md) + - [盒模型](chapter1/04_04_box_model.md) + - [背景](chapter1/04_05_background.md) + - [布局](chapter1/04_06_layout.md) + - [变形](chapter1/04_07_transform.md) + - [动画](chapter1/04_08_animation.md) + - [常见布局样例](chapter1/04_09_layout_demo.md) +- [JavaScript 程序设计](chapter2/00_intro.md) + - [JavaScript 介绍](chapter2/01_javascript_intro.md) + - [调试器](chapter2/02_dev_tools.md) + - [基础语法](chapter2/03_basic_syntax.md) + - [类型系统](chapter2/04_data_type.md) + - [类型判断](chapter2/11_js_type_determin.md) + - [内置对象](chapter2/05_internal_object.md) + - [变量作用域](chapter2/06_scope.md) + - [表达式与运算符号](chapter2/07_statement_and_operator.md) + - [语句](chapter2/08_statement.md) + - [闭包](chapter2/09_closure.md) + - [面向对象](chapter2/10_object.md) + - [正则表达式](chapter2/12_reg_exp.md) +- [DOM 编程](chapter3/00_intro.md) + - [文档树(DOM Tree)](chapter3/01_dom_tree.md) + - [节点操作](chapter3/02_node_manipulation.md) + - [操作属性](chapter3/03_attribute.md) + - [样式操作](chapter3/04_style_manipulation.md) + - [事件](chapter3/05_events.md) + - [多媒体(视频与音频)](chapter3/08_multimedia.md) + - [Canvas](chapter3/07_canvas.md) + - [BOM](chapter3/10_bom.md) + - [数据通信](chapter3/09_network.md) + - [数据存储](chapter3/11_storage.md) + - [动画](chapter3/06_animation.md) + - [表单操作](chapter3/12_form_manipulation.md) + - [列表操作](chapter3/13_list_manipulation.md) +- [页面架构](chapter4/00_intro.md) + - [CSS Reset](chapter4/01_CSS_Reset.md) + - [布局解决方案](chapter4/02_layout.md) + - [响应式布局](chapter4/03_responsive.md) + - [页面优化](chapter4/04_page_optimisation.md) + - [规范与模块化](chapter4/05_modulation.md) +- [产品前端架构](chapter5/00_intro.md) + - [协作流程](chapter5/01_collaboration.md) + - [接口设计](chapter5/02_design_api.md) + - [版本控制](chapter5/03_version_control.md) + - [技术选型](chapter5/04_tech_selection.md) + - [开发实践](chapter5/05_development.md) +- [附录 A:书单](Booklist.md) diff --git a/SampleCode/CSS/Animation.html b/SampleCode/CSS/Animation.html new file mode 100644 index 0000000..da692ae --- /dev/null +++ b/SampleCode/CSS/Animation.html @@ -0,0 +1,57 @@ + + + + + + Animation + + + + +

动画 animation

+
+
+
+ + + + diff --git a/SampleCode/CSS/AnimationPractice.html b/SampleCode/CSS/AnimationPractice.html new file mode 100644 index 0000000..97c9338 --- /dev/null +++ b/SampleCode/CSS/AnimationPractice.html @@ -0,0 +1,151 @@ + + + + + + Animation Practice + + + + +

3D 正方体组合旋转

+
+
back
+
front
+
right
+
left
+
botto
+
top
+
+ + + + diff --git a/SampleCode/CSS/Transform2D.html b/SampleCode/CSS/Transform2D.html new file mode 100644 index 0000000..2ce8dfd --- /dev/null +++ b/SampleCode/CSS/Transform2D.html @@ -0,0 +1,185 @@ + + + + + + Transform 2D + + + + +

Transform 2D

+

可忽略所有:after的样式

+

transform (translate & rotate)

+
+
+
+

translate(50%) -> rotate(45deg)

+
+
+ +
+
+
+

rotate(45deg) -> translate(50%)

+
+
+ +

translate-origin

+
+
+
+

transform-origin: 100% 100%

+
+
+ +

scale

+
+
+
+

scale(0.5)

+
+
+ +
+
+
+

rotate(45deg) scale(1.5, 2)

+
+
+ + +

skew

+
+
+
+

skew(-45deg, 45deg)

+
+
+ + + + diff --git a/SampleCode/CSS/Transform3D.html b/SampleCode/CSS/Transform3D.html new file mode 100644 index 0000000..8fcfcb7 --- /dev/null +++ b/SampleCode/CSS/Transform3D.html @@ -0,0 +1,236 @@ + + + + + + Transfomr 3D + + + + +

Transform 3D

+

可以忽略所有:after的样式

+

rotate

+
+
+
+
+
+
+ +

perspective-origin

+
+
+
+

top

+
+
+
+
+

50% 50%

+
+
+
+
+

bottom

+
+ +

translate3d(x, y, z)

+
+
+
+

(10px, 10px, 200px)

+
+
+
+
+

(0, 0, -100px)

+
+
+
+
+

(0, 0, 0)

+
+ +

scale3d

+

改变轴的比例

+
+
+
+

scale3d(1.2, 1.2, 1)

+
+ +

rotate3d

+
+
+
+

(0, 0, 1, 45deg)

+
+
+
+
+

(1, 1, 1, 45deg)

+
+
+
+
+

(-1, -1, -1, 45deg)

+
+ +

transform-style

+
+
+
+
+
+

preserve-3d

+
+ +
+
+
+
+
+

flat

+
+ +

backface-visibility

+
+
+

B

+
+
+

visible

+
+
+
+

B

+
+
+

hidden

+
+ + + + diff --git a/SampleCode/CSS/Transition.html b/SampleCode/CSS/Transition.html new file mode 100644 index 0000000..119f279 --- /dev/null +++ b/SampleCode/CSS/Transition.html @@ -0,0 +1,193 @@ + + + + + + Transition + + + + +

动画 - Transition

+

transition

+
+
+
+

无过度

+
+
+
+
+

有过度

+
+ +

transition-property

+
+
+

none

+
+
+ +
+
+

all

+
+
+ +
+
+

left

+
+
+ +
+
+

color

+
+
+ +

多个动画,多个时间

+
+
+

multipe

+
+
+ + + + diff --git a/SampleCode/Layout/00_center_horizontal.html b/SampleCode/Layout/00_center_horizontal.html new file mode 100644 index 0000000..aacc672 --- /dev/null +++ b/SampleCode/Layout/00_center_horizontal.html @@ -0,0 +1,74 @@ + + + + + 水平居中 + + + + + + +

inline-block + text-align

+
+
+
+ + + +

table + margin

+
+
+
+ + + +

absolute + transform

+
+
+
+ + + + +

flex + justify-content

+
+
+
+ + + + diff --git a/SampleCode/Layout/01_center_vertical.html b/SampleCode/Layout/01_center_vertical.html new file mode 100644 index 0000000..7320d1a --- /dev/null +++ b/SampleCode/Layout/01_center_vertical.html @@ -0,0 +1,41 @@ + + + + + + 垂直居中 + + + + + + +
+
+
+
+
+ + + + + diff --git a/SampleCode/Layout/02multiple_column.html b/SampleCode/Layout/02multiple_column.html new file mode 100644 index 0000000..0dfef6e --- /dev/null +++ b/SampleCode/Layout/02multiple_column.html @@ -0,0 +1,16 @@ + + + + + 多列布局 - 一列定宽 + + +
+
+
+
+
+
+ + + diff --git a/TOC.md b/TOC.md new file mode 100644 index 0000000..dbfaee6 --- /dev/null +++ b/TOC.md @@ -0,0 +1,68 @@ +# Summary + +- [页面制作](chapter1/00_intro.md) + - [Photoshop](chapter1/01_photoshop.md) + - [工具、面板、视图](chapter1/01_01_tool_panel_view.md) + - [测量及取色](chapter1/01_02_measurement_and_color.md) + - [切图](chapter1/01_03_slice.md) + - [图片保存](chapter1/01_04_save_image.md) + - [图片优化与合并](chapter1/01_05_image_optimisation.md) + - [开发及调试工具](chapter1/02_dev_tools.md) + - [Sublime 编辑器](chapter1/02_01_sublime.md) + - [Atom 编辑器](chapter1/02_02_atom.md) + - [HTML](chapter1/03_html.md) + - [HTML 简介](chapter1/03_01_html_intro.md) + - [HTML 语法](chapter1/03_02_html_sytax.md) + - [HTML 标签](chapter1/03_05_html_tags.md) + - [实体字符](chapter1/03_03_html_ascii_encoding.md) + - [浏览器兼容](chapter1/03_04_cross_browser.md) + - [CSS](chapter1/04_css_intro.md) + - [语法](chapter1/04_01_css_sytax.md) + - [选择器](chapter1/04_02_selector.md) + - [文本](chapter1/04_03_text.md) + - [盒模型](chapter1/04_04_box_model.md) + - [背景](chapter1/04_05_background.md) + - [布局](chapter1/04_06_layout.md) + - [变形](chapter1/04_07_transform.md) + - [动画](chapter1/04_08_animation.md) + - [常见布局样例](chapter1/04_09_layout_demo.md) +- [JavaScript 程序设计](chapter2/00_intro.md) + - [JavaScript 介绍](chapter2/01_javascript_intro.md) + - [调试器](chapter2/02_dev_tools.md) + - [基础语法](chapter2/03_basic_syntax.md) + - [类型系统](chapter2/04_data_type.md) + - [类型判断](chapter2/11_js_type_determin.md) + - [内置对象](chapter2/05_internal_object.md) + - [变量作用域](chapter2/06_scope.md) + - [表达式与运算符号](chapter2/07_statement_and_operator.md) + - [语句](chapter2/08_statement.md) + - [闭包](chapter2/09_closure.md) + - [面向对象](chapter2/10_object.md) + - [正则表达式](chapter2/12_reg_exp.md) +- [DOM 编程](chapter3/00_intro.md) + - [文档树(DOM Tree)](chapter3/01_dom_tree.md) + - [节点操作](chapter3/02_node_manipulation.md) + - [操作属性](chapter3/03_attribute.md) + - [样式操作](chapter3/04_style_manipulation.md) + - [事件](chapter3/05_events.md) + - [多媒体(视频与音频)](chapter3/08_multimedia.md) + - [Canvas](chapter3/07_canvas.md) + - [BOM](chapter3/10_bom.md) + - [数据通信](chapter3/09_network.md) + - [数据存储](chapter3/11_storage.md) + - [动画](chapter3/06_animation.md) + - [表单操作](chapter3/12_form_manipulation.md) + - [列表操作](chapter3/13_list_manipulation.md) +- [页面架构](chapter4/00_intro.md) + - [CSS Reset](chapter4/01_CSS_Reset.md) + - [布局解决方案](chapter4/02_layout.md) + - [响应式布局](chapter4/03_responsive.md) + - [页面优化](chapter4/04_page_optimisation.md) + - [规范与模块化](chapter4/05_modulation.md) +- [产品前端架构](chapter5/00_intro.md) + - [协作流程](chapter5/01_collaboration.md) + - [接口设计](chapter5/02_design_api.md) + - [版本控制](chapter5/03_version_control.md) + - [技术选型](chapter5/04_tech_selection.md) + - [开发实践](chapter5/05_development.md) +- [附录 A:书单](Booklist.md) diff --git a/WebCreation/WebCreation-CSS-1.md b/WebCreation/WebCreation-CSS-1.md deleted file mode 100644 index f1f1f40..0000000 --- a/WebCreation/WebCreation-CSS-1.md +++ /dev/null @@ -1,707 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [文本](#%E6%96%87%E6%9C%AC) - - [字体](#%E5%AD%97%E4%BD%93) - - [改变字号](#%E6%94%B9%E5%8F%98%E5%AD%97%E5%8F%B7) - - [改变字体](#%E6%94%B9%E5%8F%98%E5%AD%97%E4%BD%93) - - [加粗字体](#%E5%8A%A0%E7%B2%97%E5%AD%97%E4%BD%93) - - [倾斜字体](#%E5%80%BE%E6%96%9C%E5%AD%97%E4%BD%93) - - [更改行距](#%E6%9B%B4%E6%94%B9%E8%A1%8C%E8%B7%9D) - - [font shorthand](#font-shorthand) - - [改变文字颜色](#%E6%94%B9%E5%8F%98%E6%96%87%E5%AD%97%E9%A2%9C%E8%89%B2) - - [对齐方式](#%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F) - - [文字居中](#%E6%96%87%E5%AD%97%E5%B1%85%E4%B8%AD) - - [文本垂直对齐](#%E6%96%87%E6%9C%AC%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90) - - [文本缩进](#%E6%96%87%E6%9C%AC%E7%BC%A9%E8%BF%9B) - - [格式处理](#%E6%A0%BC%E5%BC%8F%E5%A4%84%E7%90%86) - - [保留空格格式](#%E4%BF%9D%E7%95%99%E7%A9%BA%E6%A0%BC%E6%A0%BC%E5%BC%8F) - - [文字换行](#%E6%96%87%E5%AD%97%E6%8D%A2%E8%A1%8C) - - [文本装饰](#%E6%96%87%E6%9C%AC%E8%A3%85%E9%A5%B0) - - [文字阴影](#%E6%96%87%E5%AD%97%E9%98%B4%E5%BD%B1) - - [文本装饰(下划线等)](#%E6%96%87%E6%9C%AC%E8%A3%85%E9%A5%B0%EF%BC%88%E4%B8%8B%E5%88%92%E7%BA%BF%E7%AD%89%EF%BC%89) - - [高级设置](#%E9%AB%98%E7%BA%A7%E8%AE%BE%E7%BD%AE) - - [省略字符](#%E7%9C%81%E7%95%A5%E5%AD%97%E7%AC%A6) - - [更换鼠标形状](#%E6%9B%B4%E6%8D%A2%E9%BC%A0%E6%A0%87%E5%BD%A2%E7%8A%B6) - - [强制继承](#%E5%BC%BA%E5%88%B6%E7%BB%A7%E6%89%BF) -- [盒模型](#%E7%9B%92%E6%A8%A1%E5%9E%8B) - - [属性](#%E5%B1%9E%E6%80%A7) - - [width](#width) - - [height](#height) - - [padding](#padding) - - [margin](#margin) - - [margin 合并](#margin-%E5%90%88%E5%B9%B6) - - [border](#border) - - [border-radius](#border-radius) - - [overflow](#overflow) - - [box-sizing](#box-sizing) - - [box-shadow](#box-shadow) - - [outline](#outline) - - [TRBL](#trbl) - - [值缩写](#%E5%80%BC%E7%BC%A9%E5%86%99) -- [背景](#%E8%83%8C%E6%99%AF) - - [background-color](#background-color) - - [background-image](#background-image) - - [background-repeat](#background-repeat) - - [background-attachment](#background-attachment) - - [background-position](#background-position) - - [Sprite 的使用](#sprite-%E7%9A%84%E4%BD%BF%E7%94%A8) - - [linear-gradient](#linear-gradient) - - [radial-gradient](#radial-gradient) - - [repeat-*-gradient](#repeat--gradient) - - [background-origin](#background-origin) - - [background-clip](#background-clip) - - [background-size](#background-size) - - [background shorthand](#background-shorthand) - - - -### 文本 - -

See the Pen FEND_Fonts by Li Xinyang (@li-xinyang) on CodePen.

- - -#### 字体 - -##### 改变字号 - -`font-size: | | | | inherit` - -- `` 有 small large medium -- `` 有 smaller larger - -```stylus -div - font-size 12px - p#sample0 - font-size 16px - p#sample1 - font-size 2em - p#sample2 - font-size 200% -``` - -NOTE:以上两值在开发中并不常用。`2em` 与 `200%` 都为父元素默认大小的两倍(参照物为父元素的字体大小 `12px`)。 - -##### 改变字体 - -`font-family: [ | ]# ` - -`` 可选选项,但具体使用字体由浏览器决定 -- serif -- sans-serif -- cursive -- fantasy -- monospace - -```css -font-family: arial, Verdana, sans-serif; -``` - -NOTE:优先使用靠前的字体 - -##### 加粗字体 - -`font-weight: normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900` - -```css -font-weight: normal; -font-weight: bold; -``` - -##### 倾斜字体 - -`font-style: normal | italic | oblique | inherit` - -`italic` 使用字体中的斜体,而 `oblique` 在没有斜体字体时强制倾斜字体。 - -##### 更改行距 - -`line-height: normal | | | ` - -`normal` 值为浏览器决定,在1.1至1.2之间(通常设置值为1.14左右) - -```css -/* length 类型 */ -line-height: 40px; -line-height: 3em; -/* percentage 类型 */ -line-height: 300%; -/* number 类型 */ -line-height: 3; -``` - -NOTE:当`line-height`为 `number` 类型时,子类直接继承其数值(不计算直接继承)。而当为 `percentage` 类型时,子类则会先计算再显示(先计算后继承)。 - -##### font shorthand - -`font: [ [ <‘font-style’> || || <‘font-weight’> || <‘font-stretch’> ]? <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ] | caption | icon | menu | message-box | small-caption | status-bar` - -```css -font: 30px/2 "Consolas", monospace; -font: italic bold 20px/1.5 arial, serif; -font: 20px arial, serif; -``` - -NOTE:当其他值为空时,均被设置为默认值。 - -##### 改变文字颜色 - -`color: ` - -```css -element { color: red; } -element { color: #f00; } -element { color: #ff0000; } -element { color: rgb(255,0,0); } -element { color: rgb(100%, 0%, 0%); } -element { color: hsl(0, 100%, 50%); } - -/* 50% translucent */ -element { color: rgba(255, 0, 0, 0.5); } -element { color: hsla(0, 100%, 50%, 0.5); } - -/* 全透明 */ -element { color: transparent' } -element { color: rgba(0, 0, 0, 0); } -``` - -#### 对齐方式 - -##### 文字居中 - -`text-align: start | end | left | right | center | justify | match-parent | start end` - -NOTE:默认为文本左对齐。 - -##### 文本垂直对齐 - -`vertical-align: baseline | sub | super | text-top | text-bottom | middle | top | bottom | | ` - -NOTE:``的参照物为`line-height` - -##### 文本缩进 - -`text-indent: | && [ hanging || each-line ]` - -NOTE:缩进两个字可使用 `text-indent: 2em;` - -#### 格式处理 - -##### 保留空格格式 - -`white-space: normal | pre | nowrap | pre-wrap | pre-line` - -`pre` 行为同 `
` 一致。
-
-
- 
-  
-   
-   
-   
-   
-  
- 
- 
-  
-   
-   
-   
-   
-  
-  
-   
-   
-   
-   
-  
-  
-   
-   
-   
-   
-  
-  
-   
-   
-   
-   
-  
-  
-   
-   
-   
-   
-  
- 
-
 New linesSpaces and tabsText wrapping
normalCollapseCollapseWrap
nowrapCollapseCollapseNo wrap
prePreservePreserveNo wrap
pre-wrapPreservePreserveWrap
pre-linePreserveCollapseWrap
- -##### 文字换行 - -`word-wrap: normal | break-word` - -NOTE:允许长单词自动换行。 - -`word-break: normal | break-all | keep-all` - -NOTE:`break-all` 单词中的任意字母间都可以换行。 - -#### 文本装饰 - -##### 文字阴影 - -`text-shadow:none | #` 或 `text-shadow:none | [{2,3}&&?]#` - -```css -p { - text-shadow: 1px 1px 1px #000, - 3px 3px 5px blue; -} -``` - -1. value = The X-coordinate X 轴偏移像素 -2. value = The Y-coordinate Y 轴偏移像素 -3. value = The blur radius 阴影模糊半径 -4. value = The color of the shadow 阴影颜色(默认为文字颜色) - -##### 文本装饰(下划线等) - -`text-decoration: <'text-decoration-line'> || <'text-decoration-style'> || <'text-decoration-color'>` - -```css -h1.under { - text-decoration: underline; -} -h1.over { - text-decoration: overline; -} -p.line { - text-decoration: line-through; -} -p.blink { - text-decoration: blink; -} -a.none { - text-decoration: none; -} -p.underover { - text-decoration: underline overline; -} -``` - -#### 高级设置 - -##### 省略字符 - -`text-overflow: [ clip | ellipsis | ]{1,2}` - -```css -/* 常用配合 */ -text-overflow: ellipsis; -overflow: hidden; /* 溢出截取 */ -white-space: nowrap; /* 禁止换行 */ -``` - -##### 更换鼠标形状 - -`cursor: [[,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize| text | wait | help ]] | inherit` - -**常用属性** - -`cursor: [,]*[auto | default | none | help | pointer | zoom-in | zoom-out | move]` - -- `` 图片资源地址代替鼠标默认形状 -- `` 默认光标 -- `` 隐藏光标 -- `` 手型光标 -- `` -- `` -- `` - -```css -cursor: pointer; -cursor: url(image-name.cur), pointer; -/* 当 uri 失效时或者则会起作用 */ -``` - -##### 强制继承 - -`inherit` 会强制继承父元素的属性值。 - -```css -font-size: inherit; -font-family: inherit; -font-weight: inherit; -... -word-wrap: inherit; -work-break: inherit -text-showdow: inherit -``` - -NOTE:具体在使用时可查询文档 - -### 盒模型 - -

See the Pen FEND_003_BoxModel by Li Xinyang (@li-xinyang) on CodePen.

- - -#### 属性 - -![](../img/B/box-module.jpg) - -##### width - -**内容盒子宽** - -`width: | | auto | inherit` - -NOTE:通常情况下百分比得参照物为元素的父元素。`max-width` 与 `min-width` 可以设置最大与最小宽度。 - -##### height - -**内容盒子高** - -`height: | | auto | inherit` - -NOTE:默认情况元素的高度为内容高度。`max-height` 与 `min-height` 可以设置最大与最小高度。 - -##### padding - -![](../img/P/padding-sample.png) - -`padding: [ | ]{1,4} | inherit` - -##### margin - -![](../img/M/margin-sample.png) - -`margin: [ | | auto]{1,4} | inherit` - -NOTE:`margin` 默认值为 `auto` - -Trick: - -``` -/* 可用于水平居中 */ -margin: 0 auto; -``` - -###### margin 合并 - -![](../img/M/margin-merge.png) - -毗邻元素外间距(margin)会合并,既取相对较大的值。父元素与第一个和最后一个子元素的外间距也可合并。 - -##### border - -![](../img/B/border-sample.png) - -``` -border: [ || || ] | inherit -border-width: [ | thin | medium | thick]{1,4} | inherit -border-style: [solid | dashed | dotted | ...]{1,4} |inherit -border-colro: [ | transparent]{1,4} | inherit -``` - -NOTE:`border-color` 默认为元素字体颜色。 - -##### border-radius - -![](../img/B/border-radius-sample1.png) - -``` -/* 水平半径/垂直半径 */ -border-radius: [ | ]{1,4} [ / [ | ]{1,4} ]? -``` - -NOTE:四个角的分解属性由左上角顺时针附值。 - -##### overflow - -![](../img/O/overflow-sample.png) - -`overflow: visible | hidden | scroll | auto` - -NOTE:默认属性为 `visible`。使用 `overflow-x` 与 `overflow-y` 单独的设置水平和垂直方向的滚动条。 - -##### box-sizing - -![](../img/B/box-sizing.png) - -![](../img/B/box-sizing1.png) - -`box-sizing: content-box | border-box | inherit` - -- `content-box` = 内容盒子宽高 + 填充(`Padding`)+ 边框宽(`border-width`) -- `border-box` = 内容盒子宽高 - -##### box-shadow - -![](../img/B/box-shadow.png) - -`box-shadown: none | [inset? && [ ? ? ? ] ]#` - -```html -box-shadow: 4px 6px 3px 0px red; - | | | | - 水平偏移| | | - 垂直偏移 | | - 模糊半径 | - 阴影大小 -``` - -NOTE:水平与垂直偏移可以为负值即相反方向偏移。颜色默认为文字颜色。阴影不占据空间,仅为修饰效果。 - -##### outline - -``` -outline: [ <'outline-color'> || <'outline-style'> || <'outline-width'> ] -outline-width: | thin | medium | thick | inherit -outline-style: solid | dashed | dotted | ... | inherit -outline-color: | invert | inherit -/* invert 与当前颜色取反色 */ -``` - -NOTE:`outline` 与 `border` 相似但无法分别设置四个方向的属性。`outline` 并不占据空间,而 `border` 占据空间,且显示位于 `border` 以外。 - -#### TRBL - -![](../img/T/TRBL.png) - -![](../img/B/border-radius-sample.png) - -TRBL (Top, Right, Bottom, Left) 即为顺时针从顶部开始。具有四个方向的属性都可以通过 `*-top` `*-right` `*-bottom` 与 `*-left` 单独对其进行设置。 - -#### 值缩写 - -下面的值缩写以 `padding` 为例。 - -> 对面相等,后者省略;四面相等,只设一个。 - -```html -/* 四面值 */ -padding: 20px; -padding: 20px 20px 20px 20px; - -/* 上下值 右左值 */ -padding: 20px 10px; -padding: 20px 10px 20px 10px; - -/* 上值 右左值 下值 */ -padding: 20px 10px 30px; -padding: 20px 10px 30px 10px; -``` - - -### 背景 - -#### background-color - -``` -background-color: -background-color: #f00; -background-color: rgba(255, 0, 0, 0.5); -background-color: transparent; /* 默认值 */ -``` - -#### background-image - -``` -background-image: [, ]* -/* = | none */ -background-image: url("../image/pic.png"); -background-image: url("../image/pic.png0"), url("../image/pic1.png"); -/* 多张背景图时,先引入的图片在上一层后引入则在下一层 */ -``` - -NOTE:当`background-color` 与 `background-image` 共存时,背景颜色永远在最底层(于背景图片之下)。 - -#### background-repeat - -`background-repeat` 需与背景图片数量一致。 - -``` -background-repeat: [, = repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2} - -/* X 轴 Y 轴 */ -background-repeat: no-repeat repeat; -``` - -- `space` 平铺并在水平和垂直留有空隙,空隙的大小为图片均匀分布后完整覆盖显示区域的宽高 -- `round` 不留空隙平铺且覆盖显示区域,图标会被缩放以达到覆盖效果(缩放不一定等比) - -#### background-attachment - -当页面内容超过显示区域时,使用 `local` 使背景图片同页面内容一同滚动。 - -``` -background-attachment: [, ]* - = scroll | fixed | local -``` - -#### background-position - -``` -background-position: [, ]* - = [left|center|right|top|bottom||]|[left|center|right|top|bottom||] [left|center|right|top|bottom||] | [center |[left|right][|]?]&&[center |[left|right][|]?] - -/* 默认位置为 */ -background-position: 0 0; - -/* percentage 是容器与图片的百分比重合之处*/ -background-position: 20% 50%; - -/* 等同效果 */ -background-position: 50% 50%; -background-position: center center; - -background-position: 0 0; -background-position: left top; - -background-position: 100% 100%; -background-position: right bottom; - -/* 四个值时方向只为参照物 */ -background-position: right 10px top 20px; -``` - -![](../img/B/background-position.jpg) - -##### Sprite 的使用 - -```html -background-image: url(sprite.png) -background-repeat: no-repeat; -background-positon: 0 -100px -``` - -使用位置为负值将图片偏移使需要的图片位置上移并显示正确的图案。 - -#### linear-gradient - -``` -linear-gradient() -[[ | to [, ]+ - = [left | right] || [top | bottom] - = [ | ]? - -background-image: linear-gradient(red, blue); -background-image: linear-gradient(to top, red, blue); -background-image: linear-gradient(to right bottom, red, blue); -background-image: linear-gradient(0deg, red, blue); -background-image: linear-gradient(45deg, red, blue); -background-image: linear-gradient(red, green, blue); -background-image: linear-gradient(red, green 20%, blue); -``` - -![](../img/L/linear-gradient.jpg) - -#### radial-gradient - -``` -radial-gradient( [ circle || ] [ at ]? , | [ ellipse || [ | ]{2}] [ at ]? , | [ [ circle | ellipse ] || ] [ at ]? , | at , [ , ]+ ) - - = closest-corner | closest-side | farthest-corner | farthest-side - = [ | ]? - -background-image: radial-gradient(cloest-side, red, blue); -background-image: radial-gradient(circle, red, blue); -background-image: radial-gradient(circle 100px, red, blue); -background-image: radial-gradient(red, blue); -background-image: radial-gradient(100px 50px, red, blue); -background-image: radial-gradient(100px 50px at 0 0, red, blue); -background-image: radial-gradient(red, green 20%, blue); -``` - -![](../img/R/radial-gradient.jpg) - -#### repeat-*-gradient - -``` -background-image: repeating-linear-gradient(red, blue 20px, red 40px); -background-image: repeating-radial-gradient(red, blue 20px, red 40px); -``` - -![](../img/R/repeating-gradient.jpg) - -#### background-origin - -**案例模型** - -![](../img/B/background-box-model.png) - -决定背景 (0,0) 坐标与 100% 坐标的区域。默认值为 `padding-box`。 - -``` -[, ]* - = border-box | padding-box | content-box - -background-image: url(red.png); -background-repeat: no-repeat; - -background-origin: padding-box; -background-origin: border-box; -background-origin: content-box; -``` - -![](../img/B/background-origin.jpg) - -#### background-clip - -裁剪背景,默认值为`border-box`。 - -``` -[, ]* - = border-box | padding-box | content-box - -background-image: url(red.png); -background-repeat: no-repeat; - -background-clip: border-box; -background-clip: padding-box; -background-clip: content-box; -``` - -![](../img/B/background-clip.jpg) - -#### background-size - -``` -[, ]* - = [ | | auto] {1, 2} | cover | contain - -background-image: url(red.png); -background-repeat: no-repeat; -background-position: 50% 50%; - -background-size: auto; -background-size: 20px 20px; -/* % 参照物为容器*/ -background-size: 50% 50%; -/* 尽可能小,但宽度与高度不小过容器(充满容器) */ -background-size: cover; -/* 尽可能大,但宽度与高度不超过容器(最大完全显示)*/ -background-size: contain; -``` - -![](../img/B/background-size.jpg) - -#### background shorthand - -``` -[ - = || [/ ]? || || || || - -/* 两个 第一个为 background-origin */ -/* 两个 第二个为 background-clip */ -/* 只出现一个 则即是 background-origin 也是 background-clip */ - - = || <'background-color'> - -background: url(red.png) 0 0/20px 20px no-repeat, url(blue.png) 50% 50%/contain no-repeat content-box green; -``` - -![](../img/B/background-shorthand.png) diff --git a/WebCreation/WebCreation-CSS-2.md b/WebCreation/WebCreation-CSS-2.md deleted file mode 100644 index 3103125..0000000 --- a/WebCreation/WebCreation-CSS-2.md +++ /dev/null @@ -1,856 +0,0 @@ - - -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* - -- [布局](#%E5%B8%83%E5%B1%80) - - [display](#display) - - [display:block](#displayblock) - - [display:inline](#displayinline) - - [display:inline-block](#displayinline-block) - - [display:none](#displaynone) - - [position](#position) - - [position:relative](#positionrelative) - - [position:absolute](#positionabsolute) - - [position:fixed](#positionfixed) - - [top/right/bottom/left](#toprightbottomleft) - - [z-index](#z-index) - - [z-index 栈](#z-index-%E6%A0%88) - - [float](#float) - - [clear](#clear) - - [flex](#flex) - - [flex 方向](#flex-%E6%96%B9%E5%90%91) - - [flex-direction](#flex-direction) - - [flex-wrap](#flex-wrap) - - [flex-flow](#flex-flow) - - [order](#order) - - [flex 弹性](#flex-%E5%BC%B9%E6%80%A7) - - [flex-basis](#flex-basis) - - [flex-grow](#flex-grow) - - [flex-shrink](#flex-shrink) - - [flex](#flex-1) - - [flex 对齐](#flex-%E5%AF%B9%E9%BD%90) - - [justify-content](#justify-content) - - [align-items](#align-items) - - [align-self](#align-self) - - [align-content](#align-content) -- [变形](#%E5%8F%98%E5%BD%A2) - - [2D 变形](#2d-%E5%8F%98%E5%BD%A2) - - [transform](#transform) - - [rotate()](#rotate) - - [transform-origin](#transform-origin) - - [translate()](#translate) - - [scale()](#scale) - - [skew()](#skew) - - [3D 变形](#3d-%E5%8F%98%E5%BD%A2) - - [rotateY()](#rotatey) - - [perspective](#perspective) - - [perspective-origin](#perspective-origin) - - [translate3d()](#translate3d) - - [scale3d()](#scale3d) - - [rotate3d()](#rotate3d) - - [transform-style](#transform-style) - - [backface-visibility](#backface-visibility) -- [动画](#%E5%8A%A8%E7%94%BB) - - [transition](#transition) - - [transition-property](#transition-property) - - [transition-duration](#transition-duration) - - [transition-delay](#transition-delay) - - [transition-timing-function](#transition-timing-function) - - [animation](#animation) - - [animation-name](#animation-name) - - [animation-duration](#animation-duration) - - [animation-timing-function](#animation-timing-function) - - [animation-iteration-count](#animation-iteration-count) - - [animation-direction](#animation-direction) - - [animation-play-state](#animation-play-state) - - [animation-delay](#animation-delay) - - [animation-fill-mode](#animation-fill-mode) - - [@keyframes](#@keyframes) - - - - -### 布局 - -Firefox 布局可视化 **Gecko Reflow Visualisation**,布局是指浏览器将元素以正确的大小摆放在正确的位置上。 - -#### display - -设置元素的显示方式 - -|display|默认宽度|可设置宽高|起始位置| -|-------|--------|----------|--------| -|block|父元素宽度|是|换行| -|inline|内容宽度|否|同行| -|inline-block|内容宽度|是|同行| - -##### display:block - -- 默认宽高为父元素宽高 -- 可设置宽高 -- 换行显示 - -##### display:inline - -- 默认宽度为内容宽度 -- 不可设置宽高 -- 同行显示(元素内部可换行) - -##### display:inline-block - -- 默认宽度为内容宽度 -- 可设置宽高 -- 同行显示 -- 整块换行 - -##### display:none - -- 设置元素不显示 - -`display:none` 与 `visibility:hidden` 的区别为 `display:none` 不显示且不占位,但 `visibility:hidden` 不显示但占位。 - -![](../img/G/gecko-reflow-visualisation.gif) - -#### position - -`position` 用于设置定位的方式与`top` `right` `bottom` `left` `z-index` 则用于设置参照物位置(必须配合定位一同使用)。 - -``` -position: static | relative | absolute | fixed -/* 默认值为 static */ - -``` - -##### position:relative - -- 相对定位的元素仍在文档流之中,并按照文档流中的顺序进行排列。 -- 参照物为元素本身的位置。 - -NOTE:最常用的目的为改变元素层级和设置为绝对定位的参照物。 - -![](../img/P/position-relative.png) - -##### position:absolute - -- 默认宽度为内容宽度 -- 脱离文档流 -- 参照物为第一个定位祖先或根元素(HTML 元素) - -![](../img/P/position-absolute.png) - -##### position:fixed - -- 默认宽度为内容宽度 -- 脱离文档流 -- 参照物为视窗 - -NOTE:宽高的100%的参照依然为视窗(例:网页遮罩效果) - -![](../img/P/position-fixed.png) - -##### top/right/bottom/left - -![](../img/L/layout-position.png) - -其用于设置元素边缘与参照物边缘的距离,且设置的值可为负值。在同时设置相对方向时,元素将被拉伸。 - -##### z-index - -其用于设置 Z 轴上得排序,默认值为 0 但可设置为负值。(如不做设置,则按照文档流的顺序排列。后面的元素将置于前面的元素之上) - -![](../img/L/layouy-position-zindex.png) - -###### z-index 栈 - -父类容器的 `z-index` 优于子类 `z-index` 如图 - -![](../img/L/layout-position-zindex-stack.jpg) - -#### float - -其可实现块级元素同行显示并存在于文档流之中。 - -``` -float: left | right | none | inherit -``` - -- 默认宽度为内容宽度 -- 脱离文档流(会被父元素边界阻挡与`position`脱离文档流的方式不同) -- 指的方向一直移动 - -![](../img/F/float-right.png) - -**float 元素在同一文档流中**,当同时进行 `float` 时它们会按照文档流中的顺序排列。(当所有父元素中的所有元素脱离文档流之后,父元素将失去原有默认的内容高度) - -![](../img/F/float-right-all.jpg) - -**float 元素是半脱离文档流的**,对元素是脱离文档流,但对于内容则是在文档流之中的(既元素重叠但内容不重叠)。 - -![](../img/F/float-half-off.png) - -##### clear - -``` -clear: both | left | right | none | inherit -``` - -- 应用于后续元素 -- 应用于块级元素(block) - -**使用方法**: - -1. 浮动后续空白元素 `.emptyDiv {clear: both}` -1. clearfix 于父元素 - -``` -/* clearfix */ -.clearfix:after { - content: "."; /* Older browser do not support empty content */ - visibility: hidden; - display: block; - height: 0; - clear: both; -} -.clearfix {zoom: 1;} /* 针对 IE 不支持 :after */ -``` - -#### flex - -![](../img/F/flex-container-and-item.jpg) - -弹性布局可用于多行自适应,多列自适应,间距自适应和任意对齐。 - -**创建 flex container** - -``` -display: flex -/* 弹性容器内的均为弹性元素*/ -``` - -**flex item** - -只有弹性容器在文档流中的子元素才属于弹性元素。 - -``` -
-
Block Element
- - Inline Element - -
Absolute Block Element
- -
-``` - -##### flex 方向 - -###### flex-direction - -``` - -flex-direction: row | row-reverse | column | column-reverse -``` - -![](../img/F/flex-direciton.png) - -###### flex-wrap - -``` - -flex-wrap: nowrap | wrap | wrap-reverse -``` - -![](../img/F/flex-wrap.png) - -###### flex-flow - -`flex-flow` 为 `flex-wrap` 与 `flex-direction` 的简写,建议使用此属性(避免同时使用两个属性来修改)。 - -``` -flex-flow: <'flex-direction'> || <'flex-wrap'> -``` - -![](../img/F/flex-flow.png) - -###### order - -`order` 的值为相对的(同被设置和未被设置的值相比较),当均为设置时默认值为 0 则按照文档流中的顺序排列。 - -``` -order: - -``` - -![](../img/F/flex-order0.png) -![](../img/F/flex-order1.png) - -##### flex 弹性 - -###### flex-basis - -其用于设置 `flex-item` 的初始宽高(并作为弹性的基础)。如果 `flex-direction` 是以 `row` 排列则设置**宽**,如以 `column` 排列则设置**高**。 - -``` -flex-basis: main-size | -``` - -###### flex-grow - -伸展因子,其为弹性布局中最重要的元素之一,`flex-grow` 设置元素可用空余空间的比例。`flex-container` 先安装宽度(`flex-basis`)进行布局,如果有空余空间就按照 `flex-grow` 中的比例进行分配。 - -**Width/Height = flex-basis + flex-grow/sum(flow-grow) * remain** - -``` -flex-grow: -initial: 0 - -``` - -![](../img/F/flex-grow0.png) -![](../img/F/flex-grow1.png) -![](../img/F/flex-grow2.png) - -###### flex-shrink - -收缩因子,用于分配超出的负空间如何从可用空间中进行缩减。 - -``` -flex-shrink: -initial: 1 - -``` - -**Width/Height = flex-basis + flow-shrink/sum(flow-shrink) * remain** - -remain 为负值,既超出的区域。 - -![](../img/F/flex-shrink.png) - -###### flex - -其为 `flex-grow` `flex-shrink` `flex-basis` 的值缩写。 - -``` -flex: <'flex-grow'> || <'flex-shrink'> || <'flex-basis'> -initial: 0 1 main-size -``` - -##### flex 对齐 - -###### justify-content - -其用于设置主轴(main-axis)上的对其方式。弹性元素根据主轴(横向和纵向均可)定位所以不可使用 `left` 与 `right` 因为位置为相对的。(行为相似的属性有 `text-align`) - -``` -justify-content: flex-start | flex-end | center | space-between | space-around - -``` - -![](../img/F/flex-justify-content.png) - -###### align-items - -其用于设置副轴(cross-axis)上的对其方式。(行为相似的属性有 `vertical-align`) - -``` -align-items: flex-start | flex-end | center | baseline | stretch - -``` - -![](../img/F/flex-align-items.png) - -###### align-self - -其用于设置单个 `flex-item` 在 cross-axis 方向上的对其方式。 - -``` -align-self: auto | flex-start | flex-end | center | baseline | stretch - -``` - -![](../img/F/flex-align-self.png) - -###### align-content - -其用于设置 cross-axis 方向上的对其方式。 - -``` -align-content:flex-start | flex-end | center | space-between | space-around | stretch - -``` - -![](../img/F/flex-align-content.png) - -### 变形 - -#### 2D 变形 - -##### transform - -`transform` 中可以写一个或多个方法。 - -``` -trnasform: none | + -transform: none - -transform: + - -transform: translate(50%) rotate(45deg); -transform: rotate(45deg) transform(50%) - -``` - -![](../img/T/transform-transform-function.png) - -###### rotate() - -``` -rotate() - -rotate(45deg); - -rotate(-60deg); - -``` - -![](../img/T/transform-rotate.png) - -###### transform-origin - -其用于设置原点的位置(默认位置为元素中心)第一值为 X 方向,第二值为 Y 方向, 第三值为 Z 方向。(当值空出未写的情况下默认为 50%) - -``` -transform-origin: [ | | left | center | right | top | bottom] | [ [ | | left | center | right ] && [ | | top | center | bottom ] ] ? - - - -transform-origin: 50% 50%; -transform-origin: 0 0; -transform-origin: right 50px 20px; -transform-origin: top right 20px; -``` - -![](../img/T/transform-origin.png) - -###### translate() - -移动方法,参数分别代表 X 与 Y 轴的移动(偏移值均可为负值)。 - -``` -translate([, ]?) - - -translationX() -translationY() - -transform: translate(50px); -transform: translate(50px, 20%); - -transform: translate(-50px); -transform: translate(20%); -``` - -![](../img/T/transform-traslate.png) - -###### scale() - -缩放方法,参数分别代表 X 与 Y 轴的缩放(缩放值均可为小数)。当第二值忽略时,默认设置为等同第一值。 - -``` -scale( [, ]?) - -scaleX() -scaleY() - - -transform: scale(1.2); - -transform: scale(1, 1.2); - -transform: scaleX(1.2); - -transform: scaleY(1.2); -``` - -![](../img/T/transform-scale.png) - -###### skew() - -其为倾斜的方法。第一值为 Y 轴往 X 方向倾斜(逆时针),第二值为 X 轴往 Y 方向倾斜(顺时针)。(倾斜值可为负值) - -``` -skew([, ]?) - -skewX() -skewY() - -transform: skew(30deg); -transform: skew(30deg, 30deg); -transform: skewX(30deg); -transform: skewY(30deg); -``` - -![](../img/T/transform-skew.png) - -#### 3D 变形 - -##### rotateY() - -3D 空间旋转。 - -``` -transform: rotateY() -``` - -##### perspective - -其用于设置图片 Y 轴旋转后的透视效果。`` 可以理解为人眼与元素之间的距离,越紧则效果越明显。 - -``` -perspective: none | - -perspective: none; -perspective: 2000px; -perspective: 500px; -``` - -![](../img/T/transform-perspective.png) - -##### perspective-origin - -其为设定透视的角度(透视位置均可设定为负值)。 - -``` -perspective-origin: [ | | left | center | right | top | bottom] | [ [ | | left | center | right ] && [ | | top | center | bottom ] ] - -perspective-origin: 50% 50% - -perspective-origin: left bottom; -perspective-origin: 50% -800px; -perspective-origin: right; -``` - -![](../img/T/transform-perspective-origin.png) - -##### translate3d() - -``` -translate3d(, , ) - -translateX() -translateY() -translateZ() - -transform: translate3d(10px, 20%, 50px); - -transform: translateX(10px); -transform: translateY(20%); -transform: translateZ(-100px); -``` - -![](../img/T/transform-translate3d.png) - -##### scale3d() - -``` -scale3d(, , ) - -scaleX() -scaleY() -scaleZ() - -transform: scale3d(1.2, 1.2, 1); -transform: scale3d(1, 1.2, 1); -transform: scale3d(1.2, 1, 1); -transform: scaleZ(5); - -``` - -![](../img/T/transform-scale3d.png) - -##### rotate3d() - -取 X Y Z 三轴上的一点并于坐标原点连线,以连线为轴进行旋转(逆时针)。 - -``` -rotate3d(, , , ) - -rotateX() -rotateY() -rotateZ() - -transform: rotate3d(1, 0, 0, 45deg); - -transform: rotate3d(0, 1, 0, 45deg); - -transform: rotate3d(0, 0, 1, 45deg); - -transform: rotate3d(1, 1, 1, 45deg); -``` - -![](../img/T/transform-rotate3d.png) - -##### transform-style - -其用于设置保留内部的 3D 空间,原因是一个元素进行`transform`之后内部默认为`flat`。 - -``` -transform-style: flat | perserve-3d - - - -transform-style: flat; -transform-style: preserve-3d; -``` - -![](../img/T/transform-transform-style.png) - -##### backface-visibility - -其用于设置背面不可见。 - -``` -backface-visibility: visible | hidden - -backface-visibility: visible; -backface-visibility: hidden; -``` - -![](../img/T/transform-backface-visibility.png) - -### 动画 - -#### transition - -其为众多 `` 的值缩写。(当两个时间同时出现是,第一个时间为动画长度,第二个时间为动画延时) - -``` -transition: [',' ]* - - = [none | ] ||