我正在制作一个简短的脚本来展示我女朋友的礼物,但我不能亲自送。我想在点击之间添加一个暂停,这样她就不会在一秒钟内意外地浏览所有案例。
var gifty = document.getElementById("gift");
var counter = 4;
var handler = function() {
gifty.style.backgroundPosition = counter * 722 + "px " + "0px";
counter -= 1;
switch (counter) {
case 3:
document.getElementById("head2").innerHTML = "Click it again! Click it again!";
break;
case 2:
document.getElementById("head2").innerHTML = "Hmmm, what could it be?";
break;
case 1:
document.getElementById("head2").innerHTML = "Any ideas what it could be?";
break;
case 0:
document.getElementById("head2").innerHTML = "Surprise! Your new sewing mahcine is waiting for you in Doha! Hope you like it. xxxxx";
gifty.removeEventListener("click", handler);
break;
}
}
gifty.addEventListener("click", handler);