Published in: JavaScript
I have been meaning to learn how to use mootools for a while. As i already know how to use jQuery i thought a great way to learn would be to compare the 2 syntaxes side by side.
I'm sure there is a way of using a toggle method in mootools, so once i figure out how i will update.
/** * @author Matt Hobbs * @projectDescription Comparing jQuery and mootools */ //Set jQuery into no conflict mode var $j = jQuery.noConflict(); /** * Mootools v1.11 * Click an anchor and the selected element fades from 1 to 0 The backgreound * changes to a specified color and then back again on click. */ window.addEvent('domready', function(){ //mootools domready var origBG = $('testElementM').getStyle('background-color'); var fadeColor = '#DFD1D1'; $('clickMeM').addEvent('click', function(evt){ var myFX; if($('testElementM').hasClass('faded')){ myFX = new Fx.Style('testElementM', 'opacity').start(0,1); //Create new style on selected element $('testElementM').removeClass('faded').setStyles({ 'background' : origBG }); } else { myFX = new Fx.Style('testElementM', 'opacity').start(1,0); //Create new style on selected element $('testElementM').addClass('faded').setStyles({ 'background' : fadeColor }); } new Event(evt).stop(); //Stop the event from following the link }); }); /** * jQuery v1.2.3 * Click an anchor and the selected element fades from 1 to 0 The backgreound * changes to a specified color and then back again on click. */ $j('document').ready(function(){ //jQuery domready (can also do $j(function(){}) var origBG = $j('#testElementjQ').css('background-color'); var fadeColor = '#DFD1D1'; $j('#clickMejQ').toggle(function(){ $j('#testElementjQ').fadeTo('slow', 0).css({ 'background' : fadeColor }); return false; }, function(){ $j('#testElementjQ').fadeTo('slow', 1).css({ 'background' : origBG }); return false; }); });
You need to login to post a comment.
