Friday, February 17, 2012

Multi-Transition Dart

‹prev | My Chain | next›

Today I continue to play with last night's images gallery. I hope to combine a few more animations together, if for no other reason than to see how easy it is in Dart. But first...

I keep coming across the #resource directive in the dart language spec. The spec states that they are used to "include extralinguistic resources (e.g., audio, video or graphics files)", which seems like they might be useful for an image gallery.

So I add some #resource directives to my main.dart file:
#library('image gallery');


main() {
  // ...
When I load my gallery however, I find:
Internal error: 'file:///home/cstrom/repos/dart-gallery/scripts/main.dart': Error: line 3 pos 10: Unrecognized library token
I try fiddling with the order a bit, but it seems pretty clear that, even though #resource() is in the spec, it it not yet implemented in Dartium.

Back to my regularly scheduled programming then...

The current gallery combines two animations as it moves through the list of images in the gallery. The two animations are mirrors of each other with the new image fading in while the old one fades out:

Tonight I am going to change the remove animation to shift the image to the right and behind the main image, making it smaller as it goes. I think this ought to be easy, but "ought" is usually the bane of my learning. And by bane, I mean it usually goes wildly wrong and I end up learning something.

The simple version of the remove element animation is:
removeEl(el) {
  if (el == null) return; = 'opacity 1s ease-in-out'; = "0";
  window.setTimeout(() {el.remove();}, 1000);
I try to convert this to a reusable function:
animateEl(el, property, end) { = '$property 1s ease-in-out';[property] = end
But that does not work for two reasons. First, the style property of a Dart element does not support a [] operator. Second, I am overwriting the transition property each time I use this function.

Instead I end up using the "all" property, eventually settling on the following for my animation:
removeEl(el) {
  if (el == null) return; = 'absolute'; = 'all 2s ease-out'; = '550px'; = '150px'; = '250px'; = '0.5';

  window.setTimeout(() {
  }, 7*1000);
Which does the trick:

Hrm.. I think I can turn this into a carousel. With controls and everything. Sounds like a project for tomorrow.

Day #299

No comments:

Post a Comment