尝试打鼓直到生成随机名称,然后将其移除并播放欢呼声。
这两个文件都开始正确播放,但由于某种原因,鼓声不会停止。
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
$(document).ready(function(){
var staff = [ 'hardcoded', 'list', 'of', 'staff', 'members' ];
$('button#start').click( function() {
$('embed').remove();
$('body').append('<embed id="drum-roll" src="drum-roll.wav" autostart="true" hidden="true" loop="true">');
var $display = $('#display'),
$results = $('#results table');
$display.removeClass( "winner" );
$display.addClass( "spinner" );
var counter = 0,
rand = 0,
run_time = 10,
delay = ( run_time * 100 ) / staff.length,
loop_number = 5,
max_count = staff.length * loop_number;
$display.doTimeout( 'loop', delay, function() {
counter++;
var newRand = Math.floor( Math.random() * staff.length );
if ( rand === newRand ) {
rand = Math.floor( Math.random() * staff.length );
} else {
rand = newRand;
}
$(this).text( staff[rand] );
if ( counter < max_count ) { return true; }
else {
$('#results tr:last').after('<tr><td class="number">' + staff.length + '</td><td>' + staff[rand] + '</td></tr>');
staff.remove( rand );
$display.removeClass( "spinner" );
$display.addClass( "winner" );
$('embed').remove();
$('body').append('<embed src="cheering.wav" autostart="true" hidden="true" loop="false">');
}
});
});
});
任何想法为什么会这样?我猜这与第一个embed
不在DOM中有关,还是什么?
提前致谢,