MooTools - Fx.Morph


Fx.Morph is a function provided by MooTools. It is used to create new tween for transitions between style properties. While morphing, we have to select the element with an object and then we can apply different functions to it. We also need to bind the element with a newly created tween.

Let us take an example that provides three buttons on a web page. The first one is the SET button that creates an element with style properties such as height, width, and color. The second one is the MORPH button that changes the style properties of an element. The third one is the RESET button that changes all settings to the starting position. Take a look at the following code.


<!DOCTYPE html>

      <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
      <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>
      <script type = "text/javascript">
         var morphSet = function(){
               'width': 100,
               'height': 100,
               'background-color': '#884EA0'
         var morphStart = function(){
               'width': 200,
               'height': 200,
               'background-color': '#d3715c'
         var morphReset = function(){
               'width': 0,
               'height': 0,
               'background-color': '#ffffff'
         window.addEvent('domready', function() {
            var morphElement = $('morph_element');
            var morphObject = new Fx.Morph(morphElement);
            $('set').addEvent('click', morphSet.bind(morphObject));
            $('start').addEvent('click', morphStart.bind(morphObject));
            $('reset').addEvent('click', morphReset.bind(morphObject));
      <div id = "morph_element"> </div><br/>
      <input type = "button" id = "set" value = "SET"/>
      <input type = "button" id = "start" value = "START"/>
      <input type = "button" id = "reset" value = "RESET"/>

You will receive the following output −