improve-one-two-three
$routeProvider
.when('/items/', {
//首頁
templateUrl: '/index',
controller: 'indexCtrl'
}).when('/item/:id?', {
//商品頁
templateUrl: '/item',
controller: 'itemCtrl'
}).when('/select/:id?', {
//選擇頁(方案、付款方式)
templateUrl: '/select',
controller: 'selectCtrl'
}).when('/detail/:id?', {
//填寫詳細資訊
templateUrl: '/detail',
controller: 'detailCtrl'
}).when('/success/:orderid?', {
//訂購成功
templateUrl: '/success',
controller: 'successCtrl'
})
<div when-scrolled='loadMore()'>
<div ng-repeat="item in items">
...
</div>
</div>
directive whenScrolled
捲軸位置 > 元件高度 + 緩衝區
scope.apply(attr.whenScrolled)
infinite scroll 捲軸高度動態,換頁回覆麻煩
維護手機版、電腦版功能重複(閹割版)
純 CSS all in one(~2000 lines)
修改困難
無開發慣例,樣式無法重用
各分站用 css 維護 theme(崩潰)
touch device , scroll + event 模擬
https://github.com/cubiq/iscroll - 2012
translate
http://scrollerjs.com/ - 2014
translate3d - gpu
https://github.com/zynga/scroller - game
zoom、pan..
CSS Pre compiler
SASS vs SCSS
sass framework
@mixin
@mixin
@mixin
@include
image && sprites
.red {
color:red;
}
.blue {
color:blue;
}
.bg-red {
}
.bg-blue {
}
#index {
h1 {
font-size:2em
}
.items {
background: $bg-color;
}
ul {
list-style:none;
li {
display:block;
width:100%;
height3em;
line-height:3em;
}
}
}
/ Import Plugins
@import "compass/reset";
@import "compass/css3";
@import "compass/utilities";
@import "mixins";
@import "colors";
@import "typography";
@import "partials";
@import "layout";
@import "partials/dialog";
@import "pages/index";
$logo: "/images/abc123.png";
$bg-color: #112233;
@import "main";
@include transition-property(transform);
@include transition-duration(.2s);
@include transition-timing-function(ease-in-out);
@include transform (translate(-170px));
=>
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
-webkit-transition-property: -webkit-transform;
transition-property: transform;
-moz-transition-duration: .2s;
-o-transition-duration: .2s;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-moz-transition-timing-function: ease-in-out;
-o-transition-timing-function: ease-in-out;
-webkit-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
-webkit-transform: translate(170px);
-moz-transform: translate(170px);
-ms-transform: translate(170px);
-o-transform: translate(170px);
transform: translate(170px);
@include absolute(top .6em right 1em)
=>
position: absolute;
top: .6em;
right: 1em;
.logo {
$h: image-height($logo);
$w: image-width($logo);
height: $h/$w * 160px;
width: 160px;
.mylogo {
background: url($logo);
background-size: 100% 100%;
width:100%;
height:100%;
}
}
=>
.logo {
# $h: 100;
# $w: 200;
height: 80px;
width: 160px;
.mylogo {
background: url("images/abc123.png");
background-size: 100% 100%;
width:100%;
height:100%;
}
}
@include min-width(360px) {
span {
padding:0.5em 1em 0 .5em;
}
}
+
@mixin min-width($size) {
@media screen and (min-width: $size) {
@content;
}
}
=>
@media screen and (min-width: 360px) {
span {
padding:0.5em 1em 0 .5em;
}
}
@include display-flex;
@include flex-direction(row);
@include align-items(center);
@include justify-content(center);
$ = require('gulp-load-plugins')();
gulp.task('compass', function() {
return gulp.src('scss/sites/*.scss')
.pipe($.compass({ # compile scss
image: './',
sass: 'scss'
}))
.pipe($.combineMediaQueries()) # 合併 media query
.pipe($.csso()) # 最佳化
.pipe(gulp.dest('build'));
});
gulp.task('watch', ['compass'], function () {
gulp.watch('scss/**/*.scss', ['compass']);
});
[ng-click, ng-swipe]
https://github.com/ftlabs/fastclick
FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
innerHTML vs append
https://jsperf.com/appendchild-vs-documentfragment-vs-innerhtml/24
http://ejohn.org/blog/dom-documentfragments/
https://jsperf.com/innerhtml-vs-createelement-test/6
實測結果?怪怪的。重複驗證
iphone safari:append > innerhtml
android chrome:append ~= innerhtml
PC chrome:innerhtml > append
xlist = xscroll + infinite
ng-touch menu
xscroll menu
Scroll event 在手
浮動選單
Event
注意所有小細節(延遲、異狀)
工具(profiling、jsperf)
釐清問題、搞懂原理