-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpackage_build.html
More file actions
173 lines (152 loc) · 4.67 KB
/
package_build.html
File metadata and controls
173 lines (152 loc) · 4.67 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--kissy seed for browser -->
<script src="http://g.tbcdn.cn/kissy/k/1.3.2/seed.js"></script>
<style>
body {margin:0;}
canvas {
display: block;
background: #333;
margin: 0 auto;
}
</style>
</head>
<body>
<canvas id="canvas" width="962" height="641"></canvas>
<script>
var S = KISSY;
if (S.Config.debug) {
S.config({
packages:[
{
name:"cec",
path:'../build/cec/',
charset:"utf-8",
ignorePackageNameInUri:true
}
]
});
}
S.use('cec/cec', function (S, CEC) {
var Ticker = CEC.Ticker,
RectSprite = CEC.Sprite.Rect,
AnimSprite = CEC.Sprite.Anim;
var stage = new RectSprite('canvas');
var bg1 = new RectSprite({
x: 0,
y: 0,
width: 962,
height: 171,
backgroundImage: './images/package/pkg_01.jpg',
backgroundRepeat: 'no-repeat'
}).appendTo(stage);
var bg2 = new RectSprite({
x: 0,
y: 435,
width: 962,
height: 205,
backgroundImage: './images/package/pkg_05.png',
backgroundRepeat: 'no-repeat'
}).appendTo(stage);
var repeat = new RectSprite({
x: 0,
y: 171,
width: 962,
height: 265,
backgroundImage: './images/package/repeat.png',
backgroundRepeat: 'repeat-x',
backgroundSize: 'auto 100%'
}).appendTo(stage)
.on('render:before', function (dt) {
this.setBackgroundPositionX('-5');
});
var pkgCont = new RectSprite({
x: 0,
y: 170,
width: 962,
height: 250
}).appendTo(stage);
function addPkgs (x) {
x = x || 1000;
var pkg = new AnimSprite({
name: 'package',
x: x,
y: 0,
width: 300,
height: 250,
backgroundImage: './images/package/4.png',
// animConfig 如果包涵imgWidth, imgHeight 字段,不配置frameData的话,会自动依据图片高宽 和 帧排列方向生成frame 数据
animConfig: {
autoPlay: false,
frameNum: 4,
frameRate: 8,
loop: false,
imgWidth: 2002,
imgHeight: 502,
arrangeDir: 'h'
}
}).appendTo(pkgCont)
.on('render:before', function (dt) {
this.setX('-5');
});
}
function checkPkgs () {
for (var i = 0; i < pkgCont.children.length; i ++) {
var o = pkgCont.children[i];
o.x < -300 && o.remove();
}
if (pkgCont.children.length < 4) {
var n = 4 - pkgCont.children.length;
for (var i = 0; i < n; i ++) {
addPkgs(pkgCont.children[pkgCont.children.length-1].x + 350);
}
}
}
addPkgs();
stage.delegate('click', function (e) {
if (e.targetSprite.name == 'package') {
e.targetSprite.play();
}
}).delegate('touchstart', function (e) {
if (e.targetSprite.name == 'package') {
e.targetSprite.play();
}
});
Ticker.singleton.on('tick', function (dt) {
stage.clear();
checkPkgs();
stage.render(dt);
});
//resize
window.addEventListener('resize', function () {
resize();
}, false)
var canvasEl = document.getElementById('canvas'),
oldWidth = canvasEl.width,
oldHeight = canvasEl.height;
function resize () {
var w = oldWidth,
h = oldHeight;
if (window.innerWidth/window.innerHeight > oldWidth/oldHeight) {
h = window.innerHeight;
w = oldWidth*h/oldHeight;
} else {
w = window.innerWidth;
h = oldHeight*w/oldWidth;
}
canvasEl.width = w;
canvasEl.height = h;
//console.log(w/oldWidth, h/oldHeight);
stage.setScale(w/oldWidth, h/oldHeight);
stage.moveTo((w-oldWidth)/2, (h-oldHeight)/2)
}
resize();
});
document.addEventListener('touchmove', function (e) {
e.preventDefault();
}, false)
</script>
</body>
</html>