为什么我的mouseOver函数不起作用?

时间:2014-06-29 02:29:28

标签: javascript jquery html function mouseover

游戏很简单,你点击开始按钮开始然后沿着轨道移动你的鼠标直到你到达结束然后计时器停止并显示你的分数。如果你走出赛道,你得分为零。

为什么我的mouseOver功能不起作用? 链接到我的完整代码:http://www.codecademy.com/TictacTactic/codebits/AQBK4L/edit

提前谢谢!

var score = 1000;
var timer = setInterval(countDown(), 1000);

$(document).ready(function() {
$('#start').click(function() {
    $('#game').mouseover(function() {
        stopTimer();
        score = 0
        $('#points').html(score)
    });
    $('#end').mouseover(function() {
        stopTimer()
        $('#points').html(score)
});
});
});
function countDown() {
score = score - 1;
}

function stopTimer() {
clearInterval(timer);
}

2 个答案:

答案 0 :(得分:0)

大多数活动都是小写的,例如mouseovermouseout等。还有其他活动有大写字母,例如DOMContentLoaded。大多数(如果不是全部)编程语言都区分大小写,请注意这些。

答案 1 :(得分:0)

试试这个

    var clicked = false;

$('#start').click(function() {
    if(!clicked){
        clicked = true;         
    }
});

$("#game").hover(function(){
    if(clicked){
        stopTimer();
        score = 0;
        $("#points").html(score);
    }
});
$("#end").hover(function(){
    if(clicked){
        stopTimer();
        $("#points").html(score);
    }
});

然后如果你不想让悬停事件工作,只需设置点击为假I.E:clicked = false;

相关问题