2
<html lang="en" class="yui3-loading">
5
<title>Animated Drop Targets</title>
6
<script src="../../build/yui/yui-min.js"></script>
12
border: 1px solid black;
13
background-color: #00B8BF;
19
border: 1px solid black;
20
background-color: #004C6D;
28
background-color: #D00050;
29
border: 1px solid black;
34
.anim.yui3-dd-drop-over {
35
background-color: #EDFF9F;
38
background-color: white;
40
#drag1.yui3-dd-drag-over {
42
filter: alpha(opacity=50);
48
<body class="yui3-skin-sam">
52
<div id="drag">Drag #1</div>
54
<div id="anim1" class="anim">Anim #1</div>
55
<div id="anim2" class="anim">Anim #2</div>
56
<div id="anim3" class="anim">Anim #3</div>
57
<div id="anim4" class="anim">Anim #4</div>
58
<div id="anim5" class="anim">Anim #5</div>
62
<script type="text/javascript">
63
YUI().use('dd', 'dd-plugin', 'dd-drop-plugin', 'anim', function(Y) {
65
var d = Y.one('#drag');
66
d.plug(Y.Plugin.Drag, { dragMode: 'intersect' });
68
//Get all the divs with the class anim
69
var anims = Y.Node.all('div.anim');
71
anims.each(function(v, k) {
72
//Get a reference to the Node instance
76
a.plug(Y.Plugin.NodeFX);
78
a.plug(Y.Plugin.Drop);
80
//Set the attributes on the animation
90
for (var i = 0; i < n; ++i) {
92
Math.floor(Math.random()*Y.DOM.winWidth() - 60 - a.get('offsetWidth')),
93
Math.floor(Math.random()*Y.DOM.winHeight() - a.get('offsetHeight'))
99
//Do the animation 20 times
101
//Alternate it so it "bounces" across the screen
102
direction: 'alternate',
103
//Give all of them a different duration so we get different speeds.
104
duration: ((counter * 1.75) + 1)
107
//When this drop is entered, pause the fx
108
a.drop.on('drop:enter', function() {
111
//When the drop is exited, run the fx again
112
a.drop.on('drop:exit', function() {
115
//When a drop is on the node, do something special
116
a.drop.on('drop:hit', function(e) {
119
//remove the tween listener
120
this.fx.unsubscribeAll('tween');
121
//move it to the dock
130
var dW = Y.one('body').get('viewportRegion').right;
131
return ((dW - 60)); //Minus 60 for the dock
139
//We are using reverse above for the "bouncing", reset it here.
143
//On end, add a class and destroy the target
144
this.fx.on('end', function() {
145
this.drop.get('node').addClass('done');
151
//others that were dropped on.
152
Y.each(e.others, function(v, k) {
153
var node = v.get('node');
159
//on tween of the original anim, we need to sync the drop's shim.
160
a.fx.on('tween', function() {
161
//Do we have an active Drag?
162
if (Y.DD.DDM.activeDrag) {
164
this.drop.sizeShim();
165
//Force an over target check since we might not be moving the mouse.
166
Y.Lang.later(0, a, function() {
167
this.drop._handleTargetOver();