Fx.Events provides some options to raise some codes at different
levels throughout the animation effect. It provides you the control over
your tweens and morphs. The option that Fx.Events provides −
The second one is the onComplete() method which highlights the div when mouse pointer leaves the div area. And when the mouse pointer enters into the div area automatically the div size increases by 400px. We will try to execute all these functionalities using the Fx.Events methods. Take a look at the following code.
- onStart − It will raise the code to execute when the Fx starts.
- onCancel − It will raise the code to execute when the Fx is cancelled.
- onComplete − It will raise the code to execute when the Fx is completed.
- onChainComplete − will raise the code to execute when the chained Fx completes.
Example
Let us take an example wherein, there are divs on the web page. We proceed by applying Event methods to the divs. The first method is the onStart() method to highlight the div when mouse pointer enters into the div area.The second one is the onComplete() method which highlights the div when mouse pointer leaves the div area. And when the mouse pointer enters into the div area automatically the div size increases by 400px. We will try to execute all these functionalities using the Fx.Events methods. Take a look at the following code.
<!DOCTYPE html> <html> <head> <style> #quadin { width: 100px; height: 20px; background-color: #F4D03F; border: 2px solid #808B96; } #quadout { width: 100px; height: 20px; background-color: #F4D03F; border: 2px solid #808B96; } #quadinout { width: 100px; height: 20px; background-color: #F4D03F; border: 2px solid #808B96; } </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 enterFunction = function() { this.start('width', '400px'); } var leaveFunction = function() { this.start('width', '200px'); } window.addEvent('domready', function() { var quadIn = $('quadin'); var quadOut = $('quadout'); var quadInOut = $('quadinout'); quadIn = new Fx.Tween(quadIn, { link: 'cancel', transition: Fx.Transitions.Quad.easeIn, onStart: function(passes_tween_element){ passes_tween_element.highlight('#C54641'); }, onComplete: function(passes_tween_element){ passes_tween_element.highlight('#E67F0E'); } }); quadOut = new Fx.Tween(quadOut, { link: 'cancel', transition: 'quad:out' }); quadInOut = new Fx.Tween(quadInOut, { link: 'cancel', transition: 'quad:in:out' }); $('quadin').addEvents({ 'mouseenter': enterFunction.bind(quadIn), 'mouseleave': leaveFunction.bind(quadIn) }); $('quadout').addEvents({ 'mouseenter': enterFunction.bind(quadOut), 'mouseleave': leaveFunction.bind(quadOut) }); $('quadinout').addEvents({ 'mouseenter': enterFunction.bind(quadInOut), 'mouseleave': leaveFunction.bind(quadInOut) }); }); </script> </head> <body> <div id = "quadin"> Quad : in</div><br/> <div id = "quadout"> Quad : out</div><br/> <div id = "quadinout"> Quad : in-out</div><br/> </body> </html>You will receive the following output −
No comments:
Post a Comment