Activate your free membership today | Log-in

Tuesday, September 30th, 2008

Dojo Fishtank

Category: Dojo

<>p>

Blaine Ehrhart wrote a fun little fish tank using Dojo, as another example of doing animation using JavaScript, which includes the following to give you a taste:

JAVASCRIPT:
  1.  
  2. function playBubble (target,newbubble) {
  3.         var top = parseInt(target.style.top);
  4.         var left = parseInt(target.style.left);
  5.         var rand = 50+Math.round(50*Math.random());
  6.         // Here we detect how far up the page the bubble is so we can fade it out with the dojo.fadeOut function and delete it
  7.         if (top <= 150) {
  8.                 var fadeOut = dojo.fadeOut({
  9.                         node: target,
  10.                         duration: 200,
  11.                         onEnd: function(){dojo._destroyElement(target);}
  12.                 });
  13.                 fadeOut.play();
  14.                 return true;
  15.         }
  16.         // If it's a new bubble then we want to setup it's bubble sequence to go up
  17.         if (newbubble == 1) {
  18.                 var floatUp = dojo.fx.slideTo({
  19.                         node: target,
  20.                         duration: 10000,
  21.                         properties: {
  22.                                 top: {
  23.                                         end:"-200",
  24.                                         unit:"px"
  25.                                 }
  26.                         }
  27.                 });
  28.                 floatUp.play();
  29.         }
  30.         // After many random variables are used you get a very bubbly effect when using dojo.fx.slideTo
  31.         var bubbleEffect = dojo.fx.slideTo({
  32.                 node: target,
  33.                 duration: 1000,
  34.                 properties: {
  35.                         left: {
  36.                                 end:(left%2)?(left-rand):(left+rand),
  37.                                 unit:"px"
  38.                         }
  39.                 },
  40.                 onEnd: function(){playBubble(target);}
  41.         });
  42.         bubbleEffect.play();
  43.         return true;
  44. }
  45.  

Related Content:

  • FISHTANK
    3D Fish Tank Saved...
  • IBM goes open source with Ajax
    IBM is partnering with the Open Source Dojo Foundation in its quest to improve Ajax development. Big Blue also donated code to Dojo to help jumpstart...
  • Sun gets serious about Ajax
    Sun Microsystems Inc. demonstrates a commitment to Ajax with its new involvement with to alliances working on Ajax technology, the OpenAJAX Alliance...
  • Ajax framework released
    Simplified Ajax development is the goal of a new framework from Emergetk, released under the General Public License (GPL). It is written in C# and the...
  • Hot skills: Dojo encourages Ajax innovation
    What is it? In April 2006, a reviewer provided a round-up of 50 different Ajax frameworks and toolsets - and the number has certainly increased since...

Posted by Dion Almaer at 7:30 am
1 Comment

+++--
3.6 rating from 23 votes

1 Comment »

Comments feed TrackBack URI

Ah sure, you don’t need flash as long as your animation is extremely simple. Let’s see how much JavaScript it taks to create a character with a smooth animated walk cycle and a multi-layer scrolling background. After you crash every browser except maybe chrome, try the same thing in Flash and see how simple it is.

Comment by riaguy — October 1, 2008

Leave a comment

You must be logged in to post a comment.