1
在我的拼寫遊戲中,當一個單詞完成時,它會在網格中消失。當一定數量的單詞完成時(在這種情況下爲3),整個網格淡出以顯示背後的圖像。我現在遇到的問題是當我完成第三個單詞時,直到再次單擊鼠標時纔會發生任何事情。FadeOut without click
我需要它,所以只要該單詞完成,腳本就會在沒有點擊鼠標的情況下運行。
這裏是一塊的觸發淡出代碼...
$('.drag').on('click', function(e) {
e.preventDefault();
if(animation) return;
animation = true;
setTimeout(function(){animation = false;},500);
var target = $('.drop-box.spellword:not(.occupied):first');
var targetPos = target.position();
var currentPos = $(this).offset();
var b = $(this);
if (target.length) {
target.addClass("occupied");
$(".minibutton").prop("disabled", true);
b.clone().addClass(
b.data("letter") == target.data("letter") ? "wordglow3" : "wordglow").appendTo("table").css({
background: "transparent",
position: "absolute",
top: currentPos.top,
left: currentPos.left
}).animate({
top: targetPos.top,
left: targetPos.left
}, "slow", function() {
$(this).css({
top: 0,
left: 0
}).appendTo(target);
if (!$('.drop-box.spellword:not(.occupied)').length) {
var wordIsCorrect = 0;
$('.drop-box.spellword').each(function() {
if ($(this).attr("data-letter") == $(this).find("div").attr("data-letter")) {
wordIsCorrect++;
}
});
console.log(wordIsCorrect);
console.log($('.drop-box.spellword').length);
if ($('.drop-box.spellword').length == wordIsCorrect) {
$('.drop-box.spellword').addClass('wordglow2');
$(right).val('Well Done!');
$(right).show();
audioS.play();
$('.counter').html(completeWords + '/6').show();
$(wrong).hide();
$('.minibutton').prop('disabled', false);
} else {
$('.drop-box.spellword').addClass("wordglow4").css('color', 'transparent');
$(wrong).val('Try Again');
$('.minibutton').prop('disabled');
$(wrong).show();
audioF.play();
$('.counter').html(completeWords + '/6').show();
$(right).hide();
//$('.minibutton').prop('disabled', true);
$('.drop-box.spellword')
.animate({ 'opacity': 1 }, 2000, function()
{
$(this)
.removeClass('wordglow4')
.removeClass('occupied')
.html('')
});
}
}
});
}
var completeLetters = $('.wordglow2').length;
var completeWords = (completeLetters/3);
$('.counter').html(completeWords + '/6');
if (completeWords == 3) {
$('table').fadeOut(2000);
}
var incompleteWords = $('.spellword').hasClass('.wordglow4').length;
if (incompleteWords == 3) {
$('.minibutton').prop('disabled', false);
}
});
謝謝!
SO的人正在寫你的整個遊戲; – Asciiom
那段代碼正在運行什麼事件?是否有更多的代碼沒有發佈? –
有整個活動@Rory McCrossan – sMilbz