我是新来的,我需要一些帮助。class="reset"
我有一个随机播放功能,通过按下标签上的重置按钮调用它img
,我需要知道如何让它从头开始加载。我的意思是当我像onload=""
在body
标签上一样加载这个页面时,因为当我第一次看这个页面时,字母按字母顺序出现,我需要从头开始打乱它们。
这是html代码:
<div id="container" class='columns'>
<div class="column" draggable="true"><header>A</header></div>
<div class="column" draggable="true"><header>B</header></div>
<div class="column" draggable="true"><header>C</header></div>
<div class="column" draggable="true"><header>D</header></div>
<div class="column" draggable="true"><header>E</header></div>
<div class="column" draggable="true"><header>F</header></div>
<div class="column" draggable="true"><header>G</header></div>
<div class="column" draggable="true"><header>H</header></div>
<div class="column" draggable="true"><header>I</header></div>
<div class="column" draggable="true"><header>J</header></div>
<div class="column" draggable="true"><header>K</header></div>
<div class="column" draggable="true"><header>L</header></div>
<div class="column" draggable="true"><header>M</header></div>
<div class="column" draggable="true"><header>N</header></div>
<div class="column" draggable="true"><header>O</header></div>
<div class="column" draggable="true"><header>P</header></div>
<div class="column" draggable="true"><header>Q</header></div>
<div class="column" draggable="true"><header>R</header></div>
<div class="column" draggable="true"><header>S</header></div>
<div class="column" draggable="true"><header>T</header></div>
<div class="column" draggable="true"><header>U</header></div>
<div class="column" draggable="true"><header>V</header></div>
<div class="column" draggable="true"><header>W</header></div>
<div class="column" draggable="true"><header>X</header></div>
<div class="column" draggable="true"><header>Y</header></div>
<div class="column" draggable="true"><header>Z</header></div>
</div>
<div class="buttons">
<a href='#' ><img class="reset" src="images/resetBtn.png" title="Resetare" ></a>
</div>
JS:
jQuery(function($){
$('img.reset').click(function(){
$('#container').shuffle();
});
});
(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);