I am writing a function for a rotating navigation with JS and jQuery. I am using a plugin called jQuery transit for animating rotation. The code works, but it is very long for such a simple function. Is there any way this can be improved?
var rotation = 0;
$('nav ul li a').bind('click', function() {
'use strict';
var item = $(this).parent();
var itemI = item.index();
var navAll = $(this).parents('ul');
var condition = rotation + '_' + itemI;
switch(condition)
{
case '0_0':
//do nothing
break;
case '0_1':
navAll.transition({rotate: '-=90deg'});
$('nav ul li a').transition({rotate:'90deg'});
rotation = 270;
break;
case '0_2':
navAll.transition({rotate: '-=180deg'});
$('nav ul li a').transition({rotate:'180deg'});
rotation = 180;
break;
case '0_3':
navAll.transition({rotate: '+=90deg'});
$('nav ul li a').transition({rotate:'-90deg'});
rotation = 90;
break;
case '90_0':
navAll.transition({rotate: '0deg'});
$('nav ul li a').transition({rotate:'0deg'});
rotation = 0;
break;
case '90_1':
navAll.transition({rotate: '-90deg'});
$('nav ul li a').transition({rotate:'90deg'});
rotation = 270;
break;
case '90_2':
navAll.transition({rotate: '+=90deg'});
$('nav ul li a').transition({rotate:'-180deg'});
rotation = 180;
break;
case '90_3':
break;
case '180_0':
navAll.transition({rotate: '0deg'});
$('nav ul li a').transition({rotate:'0deg'});
rotation = 0;
break;
case '180_1':
navAll.transition({rotate: '-90deg'});
$('nav ul li a').transition({rotate:'90deg'});
rotation = 270;
break;
case '180_2':
//do nothing
break;
case '180_3':
navAll.transition({rotate: '-=90deg'});
$('nav ul li a').transition({rotate:'-90deg'});
rotation = 90;
break;
case '270_0':
navAll.transition({rotate: '0deg'});
$('nav ul li a').transition({rotate:'0deg'});
rotation = 0;
break;
case '270_1':
//do nothing
break;
case '270_2':
navAll.transition({rotate: '-=90deg'});
$('nav ul li a').transition({rotate:'180deg'});
rotation = 180;
break;
case '270_3':
navAll.transition({rotate: '-=180deg'});
$('nav ul li a').transition({rotate:'-90deg'});
rotation = 90;
break;
}
});
$('nav ul li a')
should be put in a variable. Any other suggestions? \$\endgroup\$