這是我的js代碼。我正在嘗試製作一個TicTacToe遊戲。當玩家懸停在表格單元格上時,他們將在該單元格中看到「x」或「o」標記,並顯示50%的不透明度。當他們點擊表格單元格時,他們將在該單元格中看到一個具有100%不透明度的標記。當我將鼠標懸停在已被點擊的單元格上時,它將繼續應用懸停事件。如何在點擊後關閉懸停事件,同時保持單元格的新不透明度?我的功能的目標是能夠懸停在表格單元格上,並暫時看到50%的不透明標記,並能夠點擊表格單元並永久地看到100%不透明標記。圖片http://imgur.com/a/WaZBQ關閉後單擊並保持點擊懸停事件
注:我嘗試在我的單擊事件結束時添加一個.off函數。
$(this).off("mouseenter mouseleave);
這並不能解決我的問題。
$(".tableCell").hover(function(){
$(this).children(".tableCellMarker").attr("src", function(index, attr){
return attr.replace("", "images/X.png");
});
}, function(){
$(this).children(".tableCellMarker").attr("src", function(index, attr){
return attr.replace("images/X.png", "");
});
});
$(".tableCell").click(function(){
$(this).children(".tableCellMarker").attr("src", function(index, attr){
return attr.replace("","images/X.png");
});
$(this).children(".tableCellMarker").css("opacity",1);
$(this).addClass("marked");
});
這裏是.tableCellMarker
.marker {
cursor:pointer;
margin:-80px 0px 150px 50px;
opacity:0.5;
position:absolute;
}
你應該表現出你的HTML,並創建一個代碼段(見在編輯模式下的工具欄)。最好的祝福。 – YakovL
你的'off()'事件應該可以正常工作:http://codepen.io/anon/pen/rrxkgW –