Note that there are some explanatory texts on larger screens.

plurals
  1. POFadeOut without click
    text
    copied!<p>In my spelling game, when a word is complete it fades away in the grid. When a set amount of words are complete (in this case 3) the whole grid fades to reveal the image behind. The problem I have at the moment is when I complete the third word, nothing happens until I click the mouse again.</p> <p>I need it so as soon as that word is complete the script runs without a click of the mouse.</p> <p>Here is the piece of code that triggers the fadeOut...</p> <pre><code>$('.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); } </code></pre> <p>});</p> <p>THANKS!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload