HTML文件:
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="jquery.js"></script>
<div id="question">
<img id="fruit1" class="fruit">
</div>
我删除了重复项 单独的文件具有爆炸效果。 jquery.js 不是一个jquery库,对此感到困惑
var playing = false;
var score;
var trialsleft;
var step;
var action;
var fruits = ["apple", "arbuzas", "avocado", "banana", "berry", "carrot", "lemon", "pumpkin", "tomato"]
$(function(){ // Click on start reset button
$("#startreset").click(function(){
// We are playing
if(playing == true) {
// Reload page
location.reload();
}else{
// We are not playing
playing = true; // Game initiated
// Set score to 0
score = 0;
$("#scorevalue").html(score);
// Show trials left
$("#trialsleft").show();
trialsleft = 3;
addHearts();
//Hide game over box
$("#gameover").hide();
// Change button text to reset game
$("#startreset").html("Reset Game");
// Start sending fruits
startAction();
}
});
$("#fruit1").mouseover(function(){
score++;
$("#scorevalue").html(score); //Update score
document.getElementById("sliceSound").play(); // Play Sound
// $("#sliceSound")[0].play();
//Stop Fruit
clearInterval(action);
//Hide Fruit
$("#fruit1").hide("explode", 500); // Slice fruits
//Send new fruit
setTimeout(startAction, 500);
});
我添加了我的代码的顶部,感谢您的任何帮助和支持。 我的代码下面有函数,但是我不确定它是否有问题,我应该将其发布在这里,因为长期以来它不会让我这么做。