Advertisement
OmgImAlexis

Shuffle posts

Jan 31st, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. (function( $ ){
  2. $.fn.shuffle = function() {
  3. $('#posts').each(function(){
  4. var $ul = $(this);
  5. var $liArr = $ul.children('.entry');
  6. $liArr.sort(function(a,b){
  7. var temp = parseInt( Math.random()*10 );
  8. var isOddOrEven = temp%2;
  9. var isPosOrNeg = temp>5 ? 1 : -1;
  10. return( isOddOrEven*isPosOrNeg );
  11. })
  12. .appendTo($ul);
  13. });
  14. var msnry = new Masonry( "#posts", {
  15. itemSelector: ".entry"
  16. });
  17. };
  18. })( jQuery );
  19.  
  20. $("#shuffle").on( "click", function() {
  21. event.preventDefault();
  22. $("#posts").shuffle();
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement