1
文字圖像是假設當用戶點擊圖像以模擬淡出&淡入效果。因此,當用戶點擊圖像時,它將作爲一個動作淡出和淡入,而當用戶沒有點擊圖像時,它將不具有淡入淡出和淡入淡出效果。因此,當用戶點擊兩次圖像時,文本圖像和淡出和淡入,然後重複淡出和淡入效果。
我做了什麼:
我已經設置了以下效果,下面的代碼:
$("#TapText").click(function(){
$("#TapText").fadeOut();
});
$("#TapText").click(function(){
$("#TapText").fadeIn();
});
問題:
在一點上, image fadeIn和fadeOut,但是,fadeIn的數量並不一致點擊,因此,在每次點擊時,圖像將淡出,然後淡入淡出。
什麼是做錯了,我該如何糾正?
感謝
//Notification Countdown
function GameStartTimer() {
if (count > 0) {
$("#CountdownFadeInTimer").fadeOut('slow', function() {
// $("#CountdownFadeInTimer").text(count);
$("#GameCounter").attr("src", "lib/image/fadeInCount/" + count + ".png")
$("#CountdownFadeInTimer").fadeIn();
count--;
console.log(count);
});
} else if (count == 0) {
$("#CountdownFadeInTimer").fadeOut('slow', function() {
// $("#CountdownFadeInTimer").text("Start!!");
console.log("start");
$("#GameCounter").attr("src", "lib/image/Start.png")
$("#CountdownFadeInTimer").fadeIn();
count--;
//method call to Game function & Timer
initiateGameTimer();
//Remove the "disabled" attribute to allow user to tap on the image button when notification countdown is done
document.getElementById("TapText").removeAttribute("disabled");
});
} else {
//fade out countdown text
$("#CountdownFadeInTimer").fadeOut();
clearInterval(interval);
}
}
//Trigger to set GameStartTimer function: fade in notification counter
interval = setInterval(function() {
GameStartTimer()
}, 2000);
// Tap the star down function
function GameStart() {
console.log("GameStart");
x = document.getElementById('GameStar').offsetTop;
//check condition if star reach bottom page limit, else continue to move down
if (x < bottomStarLimit) {
console.log("x:" + x);
x = x + step;
$("#TapText").click(function() {
$("#TapText").fadeOut();
});
$("#TapText").click(function() {
$("#TapText").fadeIn();
});
}
document.getElementById('GameStar').style.top = x + "px";
}
<div id="GamePage" style="width:1920px; height:3840px; z-index=1;">
<input id="TapText" type="image" src="lib/toysrus/image/finger.png" onclick="GameStart()" disabled="disabled" />
</div>
非常感謝您的幫助!但是我的問題是什麼? – Luke
@Luke對不起,我的不好解釋..但與您的代碼這是關於[尊敬。'('點擊')和.click()之間[尊重](http://stackoverflow.com/questions/9122078/difference-between -onclick-vs-click)你可以使用.on('click')並且它也可以工作.... http://jsfiddle.net/mohamedyousef1980/9rafboyh/1/ –