|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>Animating Along a Curved Path</title> |
|
|
7 |
|
|
|
8 |
<style type="text/css"> |
|
|
9 |
/*margin and padding on body element |
|
|
10 |
can introduce errors in determining |
|
|
11 |
element position and are not recommended; |
|
|
12 |
we turn them off as a foundation for YUI |
|
|
13 |
CSS treatments. */ |
|
|
14 |
body { |
|
|
15 |
margin:0; |
|
|
16 |
padding:0; |
|
|
17 |
} |
|
|
18 |
</style> |
|
|
19 |
|
|
|
20 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
21 |
<script type="text/javascript" src="../../build/yui/yui-min.js"></script> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<!--begin custom header content for this example--> |
|
|
25 |
<link href="assets//anim.css" rel="stylesheet" type="text/css"> |
|
|
26 |
|
|
|
27 |
<!--end custom header content for this example--> |
|
|
28 |
|
|
|
29 |
</head> |
|
|
30 |
|
|
|
31 |
<body class=" yui-skin-sam"> |
|
|
32 |
|
|
|
33 |
<h1>Animating Along a Curved Path</h1> |
|
|
34 |
|
|
|
35 |
<div class="exampleIntro"> |
|
|
36 |
<p>This demonstrates how to animate the position of an element along a <code>curve</code>.</p> |
|
|
37 |
<p> Click anywhere to move the element to your click position.</p> |
|
|
38 |
|
|
|
39 |
</div> |
|
|
40 |
|
|
|
41 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
42 |
|
|
|
43 |
<span id="demo"></span> |
|
|
44 |
|
|
|
45 |
<script type="text/javascript"> |
|
|
46 |
YUI({base:"../../build/", timeout: 10000}).use("anim", function(Y) { |
|
|
47 |
var node = Y.get('#demo'); |
|
|
48 |
|
|
|
49 |
var anim = new Y.Anim({ |
|
|
50 |
node: node, |
|
|
51 |
duration: 1.5, |
|
|
52 |
easing: Y.Easing.easeOut |
|
|
53 |
}); |
|
|
54 |
|
|
|
55 |
var randomCurve = function(end) { |
|
|
56 |
var points = [], |
|
|
57 |
n = 3, |
|
|
58 |
winWidth = node.get('winWidth'), |
|
|
59 |
winHeight = node.get('winHeight'); |
|
|
60 |
|
|
|
61 |
for (var i = 0; i < n; ++i) { |
|
|
62 |
points.push([ |
|
|
63 |
Math.floor(Math.random() * winWidth), |
|
|
64 |
Math.floor(Math.random() * winHeight) |
|
|
65 |
]); |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
if (end) { |
|
|
69 |
points.push(end); |
|
|
70 |
} |
|
|
71 |
return points; |
|
|
72 |
}; |
|
|
73 |
|
|
|
74 |
var onClick = function(e) { |
|
|
75 |
anim.set('to', { |
|
|
76 |
curve: randomCurve([e.pageX, e.pageY]) |
|
|
77 |
}); |
|
|
78 |
anim.run(); |
|
|
79 |
}; |
|
|
80 |
|
|
|
81 |
Y.get('document').on('click', onClick); |
|
|
82 |
|
|
|
83 |
}); |
|
|
84 |
|
|
|
85 |
</script> |
|
|
86 |
|
|
|
87 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
88 |
|
|
|
89 |
</body> |
|
|
90 |
</html> |