Skip to content

Instantly share code, notes, and snippets.

@juarezpaf
Created January 9, 2010 20:05
Show Gist options
  • Select an option

  • Save juarezpaf/273065 to your computer and use it in GitHub Desktop.

Select an option

Save juarezpaf/273065 to your computer and use it in GitHub Desktop.
//http://css-tricks.com/random-ad-positions/
//Random Ad Positions
(function($){
$.fn.shuffle = function() {
var allElems = this.get(),
getRandom = function(max) {
return Math.floor(Math.random() * max);
},
shuffled = $.map(allElems, function(){
var random = getRandom(allElems.length),
randEl = $(allElems[random]).clone(true)[0];
allElems.splice(random, 1);
return randEl;
});
this.each(function(i){
$(this).replaceWith($(shuffled[i]));
});
return $(shuffled);
};
})(jQuery);
$(function() {
$("#ad-group-one img").shuffle();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment