Yesterday I created a tutorial showing you how you can shake an element using Fx.Shake, a MooTools component written by Aaron Newton. It turns out that jQuery UI also has a shake effect which can draw attention to an element.


<div id="shaker">
<a href=""><img src="/demo/mootools-shake.png" alt="David Walsh Blog" /></a>

Exactly the same as my MooTools method.


#shaker		{ position:fixed; top:10px; right:10px; width:299px; height:253px; display:none; }

Also exactly the same as my MooTools method.

The jQuery JavaScript

function periodical() {
	$('#shaker').effect('shake', { times:3 }, 200);
$(document).ready(function() {
	var shake = setInterval(periodical, 5000);
	$('#shaker').click(function() {

The code is basically the exact same logic ported into jQuery’s syntax and methodology. Remember that you need jQuery UI to do this.

What I loved about creating these tutorial was that these are perfect examples of how flexible these two libraries are. They both allowed me to create the same functionality in very little code. People shouldn’t focus on “jQuery against MooTools,” people should focus on “jQuery or MooTools.”

Update: Click Clear

I added clearing the interval (and thus stop the shaking) once the user has clicked on the element.