Flash without Flash: Color Slide

Since Mootools 1.2 has been released, none of my Flash without Flash stuff works with it. So here’s an updated script for the original color slide tutorial, plus a bonus enhancement.

The HTML

<ul id="nav">
  <li><a href="#">These aren't images!</a></li>
  <li><a href="#">And they aren't made with flash!</a></li>
  <li><a href="#">It's all dynamic javascript!</a></li>
</ul>

The CSS

#nav {
  margin:1em;
  list-style:none;
}
#nav a {
  font-size:24px;
  font-weight:bold;
  color:#f60;
  text-decoration:none;
  position:relative;
}
#nav a span.hover {
  color:#06f;
  position:absolute;
  top:0;
  left:0;
  cursor:pointer;
}

The Javascript

window.addEvent('load', function () {
  $$("#nav li a").each( function (el) {
      var height = el.offsetHeight;
      var width = el.offsetWidth;
      var mid = (width / 2).round();
      var hover = new Element('span', {
        "class": 'hover',
        "styles": {
          "clip": [0,mid,height,mid]
        },
        "text": el.get('text'),
        "tween": {
          "link": 'cancel',
          "duration": 600,
          "transition": 'quint:out'
        }
      }).inject(el, 'inside');
 
      el.addEvents({
        "mouseover": function () {
          hover.tween('clip', [0, width, height, 0].join(' '));
        },
        "mouseout": function () {
          hover.tween('clip', [0, mid, height, mid].join(' '));
        }
      });
    });
});

4 Responses to “Flash without Flash: Color Slide”

  1. gro

    Thank You for this update. Now it works perfect! You are doing great job with this “Flash without Flash” series. Thanks!

  2. Binny V A

    Please include a demo. Still, cool effect.

  3. Chris

    It looks exactly the same as the original so just check that out if you want to see it.

  4. JastVosmoff

    Thank you

Leave a Reply