nvm安装问题处理 nvm is not compatible with the npm config prefix option 错误

nvm 安装会报一个错:

1
2
nvm is not compatible with the npm config "prefix" option: currently set to "/Users/xxx/.nvm/versions/node/xxx”
Run `nvm use --delete-prefix xxx` to unset it.

处理方式如下:
彻底卸载已经安装的nodejs , npm,再使用brew uninstall nvm卸载nvm,

再使用 https://github.com/creationix/nvm#install-script 提供的命令安装nvm:

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

安装完成后,如果出现nvm command not found,则更新 .bash_profile 文件

1、打开terminal(终端)
2、cd ~ ( 进入当前用户的home目录)
3、open .bash_profile (打开.bash_profile文件,如果文件不存在就 创建文件:touch .bash_profile 编辑文件:open -e bash_profile)
4、直接更改弹出的.bash_profile文件内容,修改为:

1
2
3
4
source ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

5、command + s 保存文件,然后关闭
6、在terminal(终端)中输入 source .bash_profile (使用刚才更新之后的内容)

在终端输入 nvm -v 能出来结果,说明安装成功。

前端知识体系大全

HTML

HTML指超文本标记语言,标准通用标记语言下的一个应用。“超文本”就是指页面内可以包含图片、链接,甚至音乐、程序等非文字元素。
HTML标记标签通常被称为 HTML 标签 (HTML tag)

html4

  • 文本段落
    p,h1,h2,h3,blockquote,span,div,img
  • 列表
    ol,ul,li,dl,dt,dd
  • 内容元素
    strong,del,dfn,em,a,abbr,acronym,address,pre,code,tt
  • 表格
    table,caption,thead,tfoot,tbody,th,tr, td,colgroup
  • 表单
    form,input(radio,checkbox,hidden,password,text),textarea,select
  • 按钮
    button,input(button)
  • 其他
    label,html,body,area,b,br

html5

语义特性(Class:Semantic)

HTML5赋予网页更好的意义和结构。更加丰富的标签。
article,aside,audio,bdi,canvas,command,datalist,details,embed,figcaption,figure,footer,
header,hgroup,keygen,mark,meter,nav,output,progress,rp,rt,ruby,section,source,summary,time,track,video

本地存储特性(Class: OFFLINE STORAGE)

  • localStorage - 没有时间限制的数据存储
  • sessionStorage - 针对一个 session 的数据存储
  • Indexed DB
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    用法:.setItem( key, value)
    sessionStorage.setItem("key", "value");
    localStorage.setItem("site", "js8.in");

    getItem获取value用途:获取指定key本地存储的值
    用法:.getItem(key)
    var value = sessionStorage.getItem("key");
    var site = localStorage.getItem("site");

    removeItem删除key用途:删除指定key本地存储的值
    用法:.removeItem(key)
    sessionStorage.removeItem("key");
    localStorage.removeItem("site");

    clear清除所有的key/value用途:清除所有的key/value
    用法:.clear()
    sessionStorage.clear();
    localStorage.clear();

设备访问特性 (Class: DEVICE ACCESS)

Geolocation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function getLocation() {
if (navigator.geolocation) {
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};

function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
};

function error(err) {
console.log(err.message);
};

navigator.geolocation.getCurrentPosition(success, error, options);
} else {
console.log("Geolocation is not supported by this browser.")
}
}
getLocation();

连接特性(Class: CONNECTIVITY)

  • Server-Sent Event
  • WebSockets
    Server-Sent Event 即服务器单向消息传递事件,网页可以自动获取来自服务器的更新。
    WebSocket 是伴随HTML5发布的一种新协议。它实现了浏览器与服务器全双工通信(full-duplex),可以传输基于消息的文本和二进制数据。WebSocket 是浏览器中最靠近套接字的API,除最初建立连接时需要借助于现有的HTTP协议,其他时候直接基于TCP完成通信。

网页多媒体特性(Class: MULTIMEDIA)

  • Audio
  • Video

三维、图形及特效特性(Class: 3D, Graphics & Effects)

性能与集成特性(Class: Performance & Integration)

  • XMLHttpRequest2

阅读原文 Read More

使用Angularjs开发控制台类项目

核心特性:MVC、Module(模块化)、指令系统、双向数据绑定

1.MVC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!Doctype html>
<html ng-app>
<head>
<meta charset="utf-8">
<script>
function HelloAngular($scope){
$scope.greeting = {
text: "Hello"
};
}
</script>
</head>
<body>
<div ng-controller="HelloAngular">
<p>{{greeting.text}},Angular</p>
</div>
</body>
<script src="js/angular-1.3.0.js"></script>
</html>

2.Module(模块化)控制器模块化保证独立性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!Doctype html>
<html ng-app="HelloAngular">
<head>
<meta charset="utf-8">
</head>
<body>
<div ng-controller="helloAngular">
<p>{{greeting.text}},Angular</p>
</div>
</body>
<script src="js/angular-1.3.0.js"></script>
<script>
var myModule = angular.module("HelloAngular", []);

myModule.controller("helloAngular", ['$scope',
function HelloAngular($scope) {
$scope.greeting = {
text: 'Hello'
};
}
]);
</script>
</html>

3.指令系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!Doctype html>
<html ng-app="MyModule">
<head>
<meta charset="utf-8">
</head>
<body>
<hello></hello>
</body>
<script src="js/angular-1.3.0.js"></script>
<script>
var myModule = angular.module("MyModule", []);
myModule.directive("hello", function() {
return {
restrict: 'E',
template: '<div>Hi everyone!</div>',
replace: true
}
});
</script>
</html>

4.双向数据绑定 数据驱动视图示例

1
2
3
4
5
6
7
8
9
10
11
12
13
<!Doctype html>
<html ng-app>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<input ng-model="greeting.text"/>
<p>{{greeting.text}},AngularJS</p>
</div>
</body>
<script src="js/angular-1.3.0.js"></script>
</html>

项目结构与基本配置

  1. css
  2. images
  3. 其它js框架与工具引入(jq, mock等)
  4. 第三方组件引入(界面,字体,日期处理,图表,树结构等)
  5. 项目模块划分(通用,主控制台,header,sidebar,主项目功能区等)
  6. 进行路由分发的配置(main.js)

项目开发中的组件与功能模块

  1. modal框,modal框内数据交互
  2. 树结构的控制
  3. 全局搜索
  4. checkbox选中与删除等操作
  5. dataitem 编辑
  6. 分页控制
  7. tabs切换
  8. datagrid,排序,单列搜索,数据格式化

##自动化构建
grunt or webpack
grunt 配置文件

##测试 Karma

深度好文

Apicloud开发app的问题总结

1. 在调用ajax之前使用showProgress可以避免用户重复操作

1
2
3
4
5
6
api.showProgress({
title: '正在加载...',
modal: true
});
//结束后使用
api.hideProgress();

2. 标签上添加tapmode 属性会消除click的延迟,在动态生成的内容js后面要添加 api.parseTapmode();

3. 打开一个新的页面,需要先使用 openwin 然后在页面使用 openframe 可以避免卡死闪退的问题

1
2
3
4
5
6
7
api.openWin({
name: 'test',
url: 'test.html',
opaque: false,
vScrollBarEnabled:false,
slidBackEnabled: false
});

打开的内容test.html页面再使用openframe。

4. 在另外一个打开的win或者frame里面执行其他frame里面的js方法

1
2
3
4
5
api.execScript({
name : 'root',
frameName : 'frame0',
script : 'initPage();'
});

5. 在app内打开远程的网页链接,并提供基于腾讯X5引擎和WKWebView的内置浏览器服务

需要先在线上 http://www.apicloud.com/module 添加webBrowser模块,然后代码中调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var browser = api.require('webBrowser');
browser.openView({
url: url,
rect:{
x : 0,
y : headh,
w : 'auto',
h : mainh
},
progress:{
color: '#008000'
}
}, function(ret, err){

});

前端面试经典问题

1. JS事件的捕获和冒泡

下面代码执行结果的顺序:
html代码如下:

<html>
    <body>
        <div id="test">
            <ul>
                <li>捕获和冒泡</li>
            </ul>
        </div>
    </body>
</html>

javascript代码如下:

var html = document.documentElement;
var body = document.body;
var div = body.querySelector('div');
var ul = body.querySelector('ul');
var li = body.querySelector('li');

ul.addEventListener('click',callback,true);
li.addEventListener('click',callback,true);
div.addEventListener('click',callbackdiv2,true);

body.addEventListener('click',callback,false);
html.addEventListener('click',callback,false);

function callback(event){
    var target = event.currentTarget;
    console.log(target.tagName);
}

function callbackdiv(event){
    //event.stopPropagation();
    console.log("div callback");
}

//输出什么内容
//div callback ->ul->li->body->html

总结就是:先捕获,后冒泡,捕获从上到下,冒泡从下到上(形象点说法:捕获像石头沉入海底,冒泡则像气泡冒出水面)
问:假如去掉注释 event.stopPropagation(); 结果又会输出什么?
结果:事件在div元素上传播被阻止,只有div元素响应事件。(还有就是在点击空白区域的时候html元素依然响应事件)

2. 如何消除一个数组里面重复的元素?

//1. 使用indexOf判断新数组,但ie低版本不支持
function unique1(arr){
    var tmpArr = [];
    for(var i=0; i<arr.length; i++){
      //如果当前数组的第i已经保存进了临时数组,那么跳过,
      //否则把当前项push到临时数组里面
      if(tmpArr.indexOf(arr[i]) == -1){
        tmpArr.push(arr[i]);
      }
    }
    return tmpArr;
}

//2. hash查找
function unique2(arr){
    var tmpArr = [], hash = {};//hash为hash表
    for(var i=0;i<arr.length;i++){
      if(!hash[arr[i]]){//如果hash表中没有当前项
        hash[arr[i]] = true;//存入hash表
        tmpArr.push(arr[i]);//存入临时数组
      }
    }
    return tmpArr;
} 

//3. 先排序后比前后大小
Array.prototype.unique3 = function () {
        var temp = new Array();
        this.sort();
        for(i = 0; i < this.length; i++) {
          if( this[i] == this[i+1]) {
            continue;
        }
          temp[temp.length]=this[i];
        }
        return temp;
} 

//4. 正则匹配
Array.prototype.unique4 = function () {
        return this.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");
}

3. 在Javascript中什么是伪数组?如何将伪数组转化为标准数组?

//argument参数,还有像调用getElementsByTagName,document.childNodes之类
var toArray = function(s){
    try{
        //s调用Array的原型slice方法,返回一个新数组
        return Array.prototype.slice.call(s);
    } catch(e){
            var arr = [];
            for(var i = 0,len = s.length; i < len; i++){
                //arr.push(s[i]);
                   arr[i] = s[i];  //据说这样比push快
            }
             return arr;
    }
}

阅读原文 Read More

React Native入门及一些问题处理

Node.js环境安装

Reacty Native CLI安装

1
npm install -g react-native-cli

相关开发工具安装

Xcode和Android Studio、Android SDK等

开始项目

1
react-native init TestApp

mac下需要安装brew,安装watchman,安装flow。win下可忽略
项目目录下运行

1
npm start

打开ios/TestApp.xcodeproj、AndroidStudio打开android目录,待IDE加载完成后(此时要等Android Studio)点击运行按钮(此时要等Xcode),可运行模拟器
有一个问题

1
Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.Light.ActionButton'.

解决方式为:
引入android-support-v7-appcompat(在sdk下),project.properties里面的 target=android-10 改为 target=android-21(编译器版本过低) 并设置AndroidManifest.xml里面的uses-sdk android:minSdkVersion=”7” 并进行clean。

##使用纯命令行安装的问题集锦
创建项目后在命令窗口调用 react-native start,启动服务,在浏览器访问http://localhost:8081/index.android.bundle?platform=android 这个基本没有什么问题。

1 运行react-native run-android 出现异常:

1
2
3
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.android.support:appcompat-v7:23.1.1.

解决方案:安装Android Support Repository与Android Support Library。win下需使用Android SDK将各个版本的api工具进行安装(大部分报错与这些版本相关)。另外需要将support lib里面的一个maven工具包进行安装,这个会导致Could not find com.android.support:appcompat-v7:23.1.1.这个问题。表面上看是找不到这个版本的工具,其实修改后面的23.1.1. 这个版本号一点作用都没有,只能说奇葩谷歌工具包啊。这里要吐槽一下android sdk。尼玛一个东西升级了导致其他一堆东西不能用,这也太扯淡了吧。能考虑一下代码狗的感受吗!!!!

另外也可以不run-android而只是进行apk的打包,打包命令为:gradlew assembleRelease 打包碰到的问题和run-android一样需要进行排查。另外gradle配置文件的加载需要依赖网络下载。所以需要一个网路畅通的网络。

2 打包的apk在安卓机上不能安装,这个问题也比较扯淡。在项目目录下\android\app\build.gradle 文件有几个配置项目

1
2
3
4
5
6
7
8
9
10
11
12
13
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.jdapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}

这里的compileSdkVersion和buildToolsVersion改了都会导致报错。targetSdkVersion才是打包好的apk适用的安卓版本。所以要把targetSdkVersion版本数改低。

3 apk在手机上安装好了但是不能使用

打开app出现红色界面并报错ReferenceError: Can’t find variable: require(line 1 the generated bundle)。需要摇动手机在Dev Settings -> Debug server host & port for device里面输入pc的ip:端口。并使用adb工具输入命令adb reverse tcp:8081 tcp:8081 所有问题都解决了,app跑起来了。后面终于可以写react native应用了!!!

相关链接

  1. http://q.maiziedu.com/article/8853/
  2. http://blog.csdn.net/raptor/article/details/38538037
  3. http://www.cnblogs.com/meteoric_cry/p/4874517.html
  4. http://blog.csdn.net/xu_fu/article/details/48571941

IOS app开发的问题处理

  1. 包重复删除重复的依赖包即可

    1
    2
    Error building DependencyGraph:
    Error: Naming collision detected: /Users/rainzhai/workspace/ReactApp/node_modules/react-web/node_modules/fbjs/package.json collides with /Users/rainzhai/workspace/ReactApp/node_modules/react-native/node_modules/fbjs/package.json
  2. Could not connect to development server. AppDelegate.m中的jsCodeLocation 改为自己本机IP地址就可

https://github.com/facebook/react-native/issues

CSS大会的总结

本次大会的ppt都在w3ctech上: http://www.w3ctech.com/topic/1463
个人具体的学习和总结如下:

1.手机淘宝CSS实践启示录


1.1 勾三股四讲了Web Components,主要是做前端组件,实现高度复用。资料如下:
Web Components 是 W3C 定义的新标准,目前还在草案阶段。
Web Components 的核心思想就是把 UI 元素组件化,即将 HTML、CSS、JS 封装起来,使用的时候就不需要这里贴一段 HTML,那里贴一段样式,最后再贴一段 JS 了。一般来说,它其实是由四个部分的功能组成的:

  • HTML Imports
  • HTML Templates
  • Custom Elements
  • Shadow DOM

###模板
使用template标签来新建模板:

<template id="appTmpl">
... 和之前一样的内容 ...
</template>

使用下面的 JS 就可以访问到模板,并将其插入 DOM 中。

var tmpl = document.querySelector('#appTmpl');
// 取到 t 以后,可以像操作 DOM 一样随意修改其中的内容
// 然后需要从模板创建一个深拷贝(Deep Copy),将其插入 DOM
var clone = document.importNode(tmpl.content, true);
// 创建深拷贝还可以使用下面的方法:
// var clone = tmpl.content.cloneNode(true);
document.body.appendChild(clone);

主要有四个特性:

  • 惰性:在使用前不会被渲染;
  • 无副作用:在使用前,模板内部的各种脚本不会运行、图像不会加载等;
  • 内容不可见:模板的内容不存在于文档中,使用选择器无法获取;
  • 可被放置于任意位置:即使是 HTML 解析器不允许出现的位置,例如作为 select 的子元素。

###Shadow DOM
Shadow DOM 是一个 HTML 的新规范,其允许开发者封装自己的 HTML 标签、CSS 样式和 JavaScript 代码。使用 Shadow DOM,我们需要在一个元素上创建一个根(Root),然后将模板内文档添加到这个根上即可。

<template id="appTmpl">
  <style>
  /* ... 将 CSS 移动到模板内 ... */
  </style>
  ... 原来的模板内容 ...
</template>
<div class="app"></div> 
var tmpl = document.querySelector('#appTmpl');
var host = document.querySelector('.app');
var root = host.createShadowRoot();
root.appendChild(document.importNode(tmpl.content, true));

###自定义元素Custom Elements
自定义元素允许开发者定义新的 HTML 元素类型。带来以下特性:

  • 定义新元素
  • 元素继承
  • 扩展原生 DOM 元素的 API
    使用 document.registerElement() 创建一个自定义元素:
var Helloworld = document.registerElement("hello-world", {
  prototype: Object.create(HTMLElement.prototype)
});

document.body.appendChild(new Helloworld());
还可以进行元素继承,扩展新的api:
var MyButton = document.registerElement("my-button", {
  prototype: Object.create(HTMLButtonElement.prototype)
});
var MyButtonProto = Object.create(HTMLButtonElement.prototype);

MyButtonProto.sayhello = function() {
  alert("hello");
};

var MyButton = document.registerElement("my-button", {
  prototype: MyButtonProto
});


var myButton = new MyButton();
document.body.appendChild(myButton);

myButton.sayhello(); // alert: "hello"
使用new来进行实例化
var myButton = new MyButton();
myButton.innerHTML = 'click me!';
document.body.appendChild(myButton);
或者在页面使用标签:
<my-button>click me!</my-button>

生命周期
元素可以定义特殊的方法,来注入其生存周期内的关键时间点。生命周期的回调函数名称和时间点对应关系如下:

  • createdCallback: 创建元素实例时
  • attachedCallback: 向文档插入实例时
  • detachedCallback: 从文档移除实例时
  • attributeChangedCallback(attrName, oldVal, newVal): 添加,移除,或修改一个属性时

    var MyButtonProto = Object.create(HTMLButtonElement.prototype);
    
    MyButtonProto.createdCallback = function() {
      this.innerHTML = 'Click Me!';
    };
    
    MyButtonProto.attachedCallback = function() {
      this.addEventListener('click', function(e) {
        alert('hello world');
      });
    };
    
    var MyButton = document.registerElement('my-button', {
      prototype: MyButtonProto
    });
    
    var myButton = new MyButton();
    document.body.appendChild(myButton);
    

    ###HTML Imports

    通过<link>标签来引入 HTML 文件,使得我们可以用不同的物理文件来组织代码。
    <link rel="import" href="http://example.com/component.html" >
    

    资料:跟 Web Components 打个啵
    http://zorro.io

1.2 勾股还讲了关于手机淘宝的响应式开发处理方案


em为单位:
这种技术需要一个参考点,一般都是以<body> 的”font-size”为基准。比如说我们使用”1em”等于”10px”来改变默认值”1em=16px”,这样一来,我们设置字体大小相当于“14px”时,只需要将其值设置为”1.4em”。
计算公式是:1 ÷ 父元素的font-size × 需要转换的像素值 = em值。
Rem为单位
CSS3的出现,他同时引进了一些新的单位,包括我们今天所说的rem。在W3C官网上是这样描述rem的——“font size of the root element” 。我在根元素 <html> 中定义了一个基本字体大小为62.5%(也就是10px。设置这个值主要方便计算,如果没有设置,将是以“16px”为基准)。从上面的计算结果,我们使用“rem”就像使用“px”一样的方便,而且同时解决了“px”和“em”两者不同之处。
lib-flexible 可伸缩布局方案
https://github.com/amfe/lib-flexible
https://www.npmjs.com/package/px2rem

  • break by-self
  • focus on the scenes
  • find a platform
  • choose the “right”
  • use the “power”
  • keep walking fast

2.New W3C CSS Checker


Mike Smith讲w3c在开搞新的css checker https://csschecker.w3.org。顺便说了下新语言Rust,确实太新了,14年底刚刚出来。顺带还透露Servo, Mozilla’s next-generation browser engine。撸码圈又多了新的语言了。。。

3.CSS 预处理器与 CSS 后处理器


###CSS 预处理器
广义上说,目标格式为 CSS 的预处理器是CSS 预处理器,但本文特指以最终生成 CSS 为目的的领域特定语言。Sass、LESS、Stylus是目前最主流的 CSS预处理器。编译前与编译后是完全不同的语言。

###CSS 后处理器
CSS 后处理器是对 CSS 进行处理,并最终生成 CSS 的预处理器,它属于广义上的CSS 预处理器。我们很久以前就在用CSS 后处理器了,最典型的例子是CSS 压缩工具(如clean-css),只不过以前没单独拿出来说过。还有最近比较火的Autoprefixer,以Can I Use上的浏览器支持数据为基础,自动处理兼容性问题。编译前与编译后的代码都是 CSS。

###优秀的 CSS 后处理器框架
1.Rework
2.PostCSS
PostCSS是一个CSS后处理器框架,允许你通过 JavaScript 对 CSS 进行修改。是从Autoprefixer项目中抽象出的框架。

###PostCSS有以下特点:
它和Rework非常相似,但提供了更高级的API,更易扩展它可以在现有Source Map的基础上生成新的Source Map在原有 CSS 格式的保留方面做的更好,便于开发编辑器插件比Rework更年轻,还只有Autoprefixer一个成功案例其实Autoprefixer最初是基于Rework做的,但后来作者有更多需求(上面的列表),就造了PostCSS这个轮子。

###用法:
安装nodejs
安装npm

npm install gulp -g
npm install postcss -g
npm install gulp-postcss -g 
npm install cssnext -g
npm install autoprefixer -g

npm install gulp --save--dev
npm install postcss --save--dev 
npm install gulp-postcss --save--dev 
npm install cssnext --save--dev
npm install autoprefixer --save--dev

新建gulpfile.js,设置解析方式:

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var cssnext = require('cssnext');
var opacity = function (css, opts) {
    css.eachDecl(function(decl) {
        if (decl.prop === 'opacity') {
            decl.parent.insertAfter(decl, {
                prop: '-ms-filter',
                value: '"progid:DXImageTransform.Microsoft.Alpha(Opacity=' + (parseFloat(decl.value) * 100) + ')"'
            });
        }
    });
};

gulp.task('css', function () {
    var processors = [
        autoprefixer({browsers: ['last 1 version']}),
        opacity,
        cssnext()
    ];
    return gulp.src('./*.css')
        .pipe(postcss(processors))
        .pipe(gulp.dest('./dest'));
});

运行gulp进行处理,后面带上task的名称:

gulp css

text.css:

.container{
    display: flex;
    opacity: .2;
}
/* 变量 */
:root {
--fontSize: 14px;
--mainColor: #333;
--highlightColor: hwb(190, 35%, 20%);
}
/* 自定义 media queries */
@custom-media --viewport-medium (min-width: 760px) and (max-width: 990px);
    /* 变量引用 以及使用 calc() 运算*/
    body {
    color: var(--mainColor);
    font-size: var(--fontSize);
    line-height: calc(var(--fontSize) * 1.5);
    padding: calc((var(--fontSize) / 2) + 1px);
    }
    /* 颜色处理函数 */
    a {
    color: color(var(--highlightColor) blackness(+20%));
    background: color(red a(80%))
    }
    /* 使用自定义 media queries */
    @media (--viewport-medium) {
    .foo {
    display: flex;
    font-size: calc(var(--fontSize) * 2 + 6px);
    }
}

生成的代码

.container{
    display: -webkit-flex;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    opacity: .2;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
}
/* 变量 */
/* 自定义 media queries */
/* 变量引用 以及使用 calc() 运算*/
body {
color: #333;
font-size: 14px;
line-height: 21px;
padding: 8px;
}
/* 颜色处理函数 */
a {
color: rgb(89, 142, 153);
background: #FF0000;
background: rgba(255, 0, 0, 0.8)
}
/* 使用自定义 media queries */
@media (min-width: 760px) and (max-width: 990px) {
    .foo {
        display: -webkit-flex;
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        font-size: 34px;
    }
}

4.Web高性能动画


该ppt深入讲解了提高网页动画性能的各种方法,关于layout,paint,composite 有个比较具体的介绍:

浏览器在渲染一个页面时,会将页面分为很多个图层,图层有大有小,每个图层上有一个或多个节点。在渲染DOM的时候,浏览器所做的工作实际上是:
1. 获取DOM后分割为多个图层
2. 对每个图层的节点计算样式结果(Recalculate style--样式重计算)
3. 为每个节点生成图形和位置(Layout--回流和重布局)
4. 将每个节点绘制填充到图层位图中(Paint Setup和Paint--重绘)
5. 图层作为纹理上传至GPU
6. 符合多个图层到页面上生成最终屏幕图像(Composite Layers--图层重组)

Chrome中满足以下任意情况就会创建图层:
* 3D或透视变换(perspective transform)CSS属性
* 使用加速视频解码的 video 节点
* 拥有3D(WebGL)上下文或加速的2D上下文的 canvas 节点
* 混合插件(如Flash)
* 对自己的opacity做CSS动画或使用一个动画webkit变换的元素
* 拥有加速CSS过滤器的元素
* 元素有一个包含复合层的后代节点(一个元素拥有一个子元素,该子元素在自己的层里)
* 元素有一个z-index较低且包含一个复合层的兄弟元素(换句话说就是该元素在复合层上面渲染)

需要注意的是,如果图层中某个元素需要重绘,那么整个图层都需要重绘。比如一个图层包含很多节点,其中有个gif图,gif图的每一帧,都会重回整个图层的其他节点,然后生成最终的图层位图。所以这需要通过特殊的方式来强制gif图属于自己一个图层(translateZ(0)或者translate3d(0,0,0)),CSS3的动画也是一样(好在绝大部分情况浏览器自己会为CSS3动画的节点创建图层)

简化一下上述过程,每一帧动画浏览器可能需要做如下工作:
1. 计算需要被加载到节点上的样式结果(Recalculate style--样式重计算)
2. 为每个节点生成图形和位置(Layout--回流和重布局)
3. 将每个节点填充到图层中(Paint Setup和Paint--重绘)
4. 组合图层到页面上(Composite Layers--图层重组)

如果我们需要使得动画的性能提高,需要做的就是减少浏览器在动画运行时所需要做的工作。最好的情况是,改变的属性仅仅印象图层的组合,变换(transform)和透明度(opacity)就属于这种情况

setTimeout的奇葩坑:

60fps是动力也是压力,因为它意味着我们只有16.7毫秒(1000 / 60)来绘制每一帧。如果使用setTimeout或者setInterval(以下统称为timer)来控制绘制,问题就来了。

首先,Timer计算延时的精确度不够。延时的计算依靠的是浏览器的内置时钟,而时钟的精确度又取决于时钟更新的频率(Timer resolution)。IE8及其之前的IE版本更新间隔为15.6毫秒。假设你设定的setTimeout延迟为16.7ms,那么它要更新两个15.6毫秒才会该触发延时。这也意味着无故延迟了 15.6 x 2 - 16.7 = 14.5毫秒。

            16.7ms
DELAY: |------------|

CLOCK: |----------|----------|
          15.6ms    15.6ms
所以即使你给setTimeout设定的延时为0ms,它也不会立即触发。目前Chrome与IE9+浏览器的更新频率都为4ms(如果你使用的是笔记本电脑,并且在使用电池而非电源的模式下,为了节省资源,浏览器会将更新频率切换至于系统时间相同,也就意味着更新频率更低)。

具体的介绍:http://www.infoq.com/cn/articles/javascript-high-performance-animation-and-page-rendering

5.重拾 CSS 的乐趣(上)


https://github.com/cssmagic/blog/issues/52

移动端事件穿透的问题处里The event through in mobile

在使用tap事件会导致手机端固定定位元素或者绝对定位元素上的点击事件会穿透到下面的元素,解决方法:
1.使用click事件
2.在tap事件上加上延时

setTimeout(function(){
    //处理逻辑
},100);

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

wordpress一些使用备注

##使用json api
可以设定跨域请求的每页数据条数

$.getJSON(prefix+"api/get_category_posts/?category_slug=game&callback=?&count=5", function(d){
});

wordpress jsonapi地址