Hi~ Summers!!

jquery shuffle (jquery function) 본문

개발/jQuery

jquery shuffle (jquery function)

eNaNII 2014. 5. 28. 11:29

출처 : https://github.com/yelotofu/lab/blob/master/jquery/snippets/shuffle/jquery.shuffle.js

 

<script type="text/javascript">

(function($){

$.fn.shuffle = function() {
return this.each(function(){
var items = $(this).children().clone(true);
return (items.length) ? $(this).html($.shuffle(items)) : this;
});
}

$.shuffle = function(arr) {
for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
return arr;
}

})(jQuery);

</script>

이렇게 하면 함수를 사용할 때 shuffle을 사용할 수 있다!

$t = $("div ul").shuffle(); 이런식으로 !!!!


shuffle 관련 링크 : http://jsfiddle.net/mW64X/


Comments