Skip to content

Commit 3ad24b3

Browse files
author
zhangxinxu
committed
optimization for animation
1. reverse instead of 'back' 2. make mobilebone.css more readable
1 parent d606b5a commit 3ad24b3

File tree

4 files changed

+160
-128
lines changed

4 files changed

+160
-128
lines changed

src/mobilebone.css

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,63 @@
88
a, img {
99
-webkit-touch-callout: none;
1010
}
11-
12-
html, body {
13-
height: 100%;
14-
-webkit-user-select: none;
11+
body {
12+
margin: 0;
13+
-webkit-user-select: none;
1514
user-select: none;
1615
-ms-touch-action: none;
17-
overflow: hidden;
1816
}
1917

20-
body { margin: 0; }
21-
22-
.page, .mask {
18+
/* construction */
19+
html, body, .page {
2320
height: 100%; width: 100%;
2421
overflow: hidden;
25-
position: absolute;
2622
}
2723
.page {
24+
position: absolute;
2825
-webkit-animation: .35s ease-in-out;
2926
animation: .35s ease-in-out;
3027
}
3128
.page.out {
3229
-webkit-transform: translateX(-100%);
3330
transform: translateX(-100%);
3431
}
32+
.page.in {
33+
-webkit-transform: translateX(0);
34+
transform: translateX(0);
35+
}
36+
37+
38+
/* mask layer when ajax sending... */
39+
.mask {
40+
height: 100%; width: 100%;
41+
background-color: rgba(255,255,255,.35);
42+
overflow: hidden;
43+
position: absolute;
44+
}
45+
.loading { /* more info: http://www.zhangxinxu.com/wordpress/?p=3357 */
46+
width: 3px; height:3px;
47+
border-radius: 100%;
48+
box-shadow: 0 -10px 0 1px #333, /* top, 1px expand */
49+
10px 0px #333, /* right */
50+
0 10px #333, /* bottom */
51+
-10px 0 #333, /* left */
52+
53+
-7px -7px 0 .5px #333, /* left-top, 0.5px expand */
54+
7px -7px 0 1.5px #333, /* right-top, 1.5px expand */
55+
7px 7px #333, /* right-bottom */
56+
-7px 7px #333; /* left-bottom */
57+
-webkit-animation: loading 1s step-start infinite;
58+
animation: loading 1s step-start infinite;
59+
}
60+
.mask > .loading {
61+
position: absolute;
62+
top: 0; right: 0; bottom: 0; left: 0;
63+
margin: auto;
64+
}
65+
66+
67+
/* Default animation - slide, you can visit '/test/transition/aniamte.css' to get more styles of animation */
3568
.slide.in {
3669
-webkit-animation-name: slideinfromright;
3770
animation-name: slideinfromright;
@@ -40,41 +73,15 @@ body { margin: 0; }
4073
-webkit-animation-name: slideouttoleft;
4174
animation-name: slideouttoleft;
4275
}
43-
.slide.back.out {
76+
.slide.reverse.out {
4477
-webkit-animation-name: slideouttoright;
4578
animation-name: slideouttoright;
4679
}
47-
.slide.back.in {
80+
.slide.reverse.in {
4881
-webkit-animation-name: slideinfromleft;
4982
animation-name: slideinfromleft;
5083
}
5184

52-
.loading { /* detail: http://www.zhangxinxu.com/wordpress/?p=3357 */
53-
width: 3px; height:3px;
54-
border-radius: 100%; /* 圆角 */
55-
box-shadow: 0 -10px 0 1px #333, /* 上, 1px 扩展 */
56-
10px 0px #333, /* 右 */
57-
0 10px #333, /* 下 */
58-
-10px 0 #333, /* 左 */
59-
60-
-7px -7px 0 .5px #333, /* 左上, 0.5px扩展 */
61-
7px -7px 0 1.5px #333, /* 右上, 1.5px扩展 */
62-
7px 7px #333, /* 右下 */
63-
-7px 7px #333; /* 左下 */
64-
-webkit-animation: loading 1s step-start infinite;
65-
animation: loading 1s step-start infinite;
66-
}
67-
68-
.mask {
69-
background-color: rgba(255,255,255,.35);
70-
}
71-
.mask > .loading {
72-
position: absolute;
73-
top: 0; right: 0; bottom: 0; left: 0;
74-
margin: auto;
75-
}
76-
77-
/* animation */
7885
@-webkit-keyframes slideinfromright {
7986
from { -webkit-transform: translateX(100%); }
8087
to { -webkit-transform: translateX(0); }
@@ -108,15 +115,7 @@ body { margin: 0; }
108115
to { transform: translateX(100%); }
109116
}
110117

111-
@-webkit-keyframes spin {
112-
from { -webkit-transform: rotate(0deg); }
113-
to { -webkit-transform: rotate(360deg); }
114-
}
115-
@keyframes spin {
116-
from { transform: rotate(0deg); }
117-
to { transform: rotate(360deg); }
118-
}
119-
118+
/* chrysanthemum loading effect */
120119
@-webkit-keyframes loading {
121120
0% { -webkit-transform: rotate(0deg); }
122121
12% { -webkit-transform: rotate(45deg); }

src/mobilebone.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
animationend: this.animationend,
134134
callback: this.callback
135135
}, params = function(element) {
136+
if (!element || !element.getAttribute) return {};
137+
136138
var _params = {}, _dataparams = (element.getAttribute("data-params") || '').queryToObject();
137139

138140
// rules as follow:
@@ -148,19 +150,19 @@
148150
return _params;
149151
};
150152

153+
// get params of each
154+
var params_out = params(pageOut), params_in = params(pageInto);
155+
151156
if (pageOut != null && pageOut.classList) {
152-
var params_out = params(pageOut);
153157
// do transition
154158
pageOut.classList.add("out");
155159
pageOut.classList.add(params_out.form);
156160
pageOut.classList.remove("in");
157161
// if reverse direction
158-
pageOut.classList[back? "add": "remove"]("back");
162+
pageOut.classList[back? "add": "remove"]("reverse");
159163

160164
}
161-
if (pageInto != null && pageInto.classList) {
162-
var params_in = params(pageInto);
163-
165+
if (pageInto != null && pageInto.classList) {
164166
// for title change
165167
var title = params_in.title, header = document.querySelector("h1");
166168
// do title change
@@ -185,7 +187,7 @@
185187
pageInto.classList.add("in");
186188
pageOut && pageInto.classList.add(params_in.form);
187189
// if reverse direction
188-
pageInto.classList[back? "add": "remove"]("back");
190+
pageInto.classList[back? "add": "remove"]("reverse");
189191

190192
// do callback when come in first time
191193
var onpagefirstinto = params_in.onpagefirstinto;

0 commit comments

Comments
 (0)