微信电影票前端工程师
Modern Web
html {
font-family: sans-serif;
}
button:focus {
outline: 0;
}
(PostCSS)
.foo {
transtion: transform 1s;
}
.foo {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s
}
Work with preprocessors (Sass, LESS)
.bar {
display: flex;
}
.bar {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex
}
// work with Gulp
gulp.task('autoprefixer', function () {
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer-core');
return gulp.src('./src/*.css')
.pipe(sourcemaps.init())
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dest'));
});
// work with Webpack
var autoprefixer = require('autoprefixer-core');
module.exports = {
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
]
},
postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ]
}
Use next generation JavaScript, today.
//ES5
function Point(x, y){
this.x = x;
this.y = y;
}
var p1 = new Point(100, 100);
//ES6
class Point{
constructor(x, y){
this.x = x;
this.y = y;
}
}
var p1 = new Point(100, 100);
Demo time
var React = require("react");
class HelloMessage extends React.Component {
render() {
return <div> Hello {this.props.name} </div>
}
}
React.render(
<HelloMessage name="ES6" />,
document.body
)
<meta name="msapplication-TileColor" content="#123456"/> <meta name="msapplication-square150x150logo" content="square.png"/>
<!-- Add to homescreen for Chrome on Android --> <meta name="mobile-web-app-capable" content="yes"> <!-- Add to homescreen for Safari on iOS --> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-title" content="Lighten"> <!-- Tile icon for Win8 (144x144 + tile color) --> <meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png"> <meta name="msapplication-TileColor" content="#3372DF"> <!-- iOS icons --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/touch/apple-touch-icon-144x144-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/touch/apple-touch-icon-114x114-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/touch/apple-touch-icon-72x72-precomposed.png"> <link rel="apple-touch-icon-precomposed" href="images/touch/apple-touch-icon-57x57-precomposed.png"> <!-- Generic Icon --> <link rel="shortcut icon" href="images/touch/touch-icon-57x57.png"> <!-- Chrome Add to Homescreen --> <link rel="shortcut icon" sizes="196x196" href="images/touch/touch-icon-196x196.png">
doctype html
html
head
// meta
include ./pagelets/head/meta.jade
Difficult to debug on Win10 Mobile
微信电影票前端工程师
User Agent 探测 (Sniffing)(uatools.js)
复杂的逻辑
很多浏览器UA互相模仿
Microsoft Edge (OS10159)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10159
Chrome
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
var browser={
versions:function(){
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}()
}
比UA 监听更科学
if (Modernizr.csstransitions) {
// Browser supports CSS Transitions
}
if (!Modernizr.canvas) {
loadCanvasPolyfill();
}
polyfill 是 shim 的一种
polyfill 特指 shim 成的 api 是遵循标准的
比如你想让IE6-8支持媒体查询
比如你想让Chrome/Safari支持Pointer Event
比如你想让IE6-9支持html5标签
<meta name="viewport" content="width=device-width, initial-scale=1.0">
对IE8或者更早的浏览器media-queries.js respond.js
来为 IE添加Media Query支持。
@charset "UTF-8"
@media screen and (max-width: 960px) {
}
@media screen and (max-width: 768px) {
}
@media screen and (max-width: 550px) {
}
@media screen and (max-width: 320px) {
}
Normalize.css 保护了有价值的默认值
Normalize.css 修复了浏览器的bug
Normalize.css 不会让你的调试工具变的杂乱
Normalize.css 是模块化的
Normalize.css 拥有详细的文档
Hey, don't be shy.