1
$(document).ready(function() {
elem = new Array('a1','a2','a3','a4','a5','a6','a7','a8','a9');
$('.graphic').hide();
hidden = false;
time = 0;
elem.sort(randomize);
$.each(elem, function(i, r) {
setTimeout(function() {
$('#'+r).fadeIn(400);
}, time);
time += 200;
});
time = 0;
//elem.sort(randomize);
setTimeout(function() {
$.each(elem, function(i, r) {
setTimeout(function() {
$('#'+r).fadeOut(800);
}, time);
time += 200;
});
$('.graphic').fadeIn(2400);
hidden = true;
}, 3000);
$('.graphic').mouseenter(function(){
if(hidden) {
//time = 0;
//elem.sort(randomize);
$('.graphic').fadeOut(400);
$.each(elem, function(i, r) {
/*setTimeout(function() {
$('#'+r).fadeIn(400);
}, time);
time += 200;*/
$('#'+r).fadeIn(400);
});
hidden = false;
}
});
$('.content').mouseenter(function(){
if(!hidden) {
time = 0;
//elem.sort(randomize);
$.each(elem, function(i, r) {
setTimeout(function() {
$('#'+r).fadeOut(800);
}, time);
time += 200;
});
$('.graphic').fadeIn(2400);
hidden = true;
}
});
$('.tile').click(function(t) {
$(this).fadeOut(800, function() {
window.location = $(this).attr("href");
}
);
return false;
});
function randomize(){
return (Math.round(Math.random())-0.5);
}
});
由於某種原因,我無法打破效果。 側面加載橫幅時隱藏。 9個元素來來去去。 每次你輸入div時,橫幅都會淡出,並且有9個div。 當我離開輸入時,會有一個隨機效果用於淡出。 但是當我進入這個效果的時候,一切都會中斷。 所以我需要在那裏休息一下,所以衰落停止,它會立即顯示我的9個div。 有什麼建議嗎? :/JS Break my隨機函數
嘗試使用動畫回調,或['.delay()'](http://api.jquery.com/delay /),而不是那麼多'setTimeout's。通過這種方式使用效果隊列,您可以輕鬆[.stop()'](http://api.jquery.com/stop/)它。 – Bergi