English 中文(简体)
MooTools - Fx.Tween
  • 时间:2024-11-03

MooTools - Fx.Tween


Previous Page Next Page  

MooTools provides different FX.Tween shortcuts for different transitions such as flashy effects which translate to smooth animated transitions. Let us discuss a few methods from the Tween shortcuts.

tween()

This method provides smooth transitions between two style property values. Let us take an example that uses tween method to change the width of a span from 100px to 300px. Take a look at the following code.

Example

<!DOCTYPE html>
<html>

   <head>
      <style>
         #body_span {
            width: 100px;
            height: 200px;
            background-color: #1A5276;
            border: 3px sopd #dd97a1;
         }
      </style>
      
      <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 tweenFunction = function(){
            $( body_span ).tween( width , 300px );
         }
         
         window.addEvent( domready , function() {
            $( tween_button ).addEvent( cpck , tweenFunction);
         });
      </script>
   </head>
   
   <body>
      <span id = "body_span"> </span><br/>
      <input type = "button" id = "tween_button" value = "Set Width to 300 px"/>
   </body>
   
</html>

You will receive the following output −

Output