The key part of jQuery code is loaded into the page footer.
Please pay attention to the authors' comment on the script or find the author's permission for reuse.
var lastUsed; function randomFrom(arr){ var randomIndex = Math.floor(Math.random() * arr.length); lastUsed = arr[randomIndex]; return lastUsed; } color_classes = ['green','purple','violet','teal','pink']; function initLinks() { $('#wrap a').hover(function() { new_classes = color_classes.slice(); var index = $.inArray(lastUsed, new_classes); new_classes.splice(index, 1); var classes = $(this).attr('class'); if (classes) { classes.split(' '); $(classes).each(function(i, className) { var index = $.inArray(className, new_classes); if (index>0) { new_classes.splice(index, 1); } }); } $(this).removeClass(color_classes.join(' ')).addClass(randomFrom(new_classes)); }, function () { }); }
source share