这是我的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 –