【发布时间】:2011-09-07 09:21:30
【问题描述】:
基本上,我将翻转从我的 css 转换为 javascript。我还选择了加载页面后要选择的一张图片。但是我遇到了 onMouseOut 事件的问题。除了那张照片,一切都很完美。当我将鼠标悬停在其他图片上时,该图片仍处于选中状态。我尝试了多种方法,但不知道如何解决.. 有什么想法吗?
<script type="text/javascript">
window.onload=function(){
clicked3();
}
function clicked3(){
document.getElementById("clicked3").style.backgroundPosition = "-198px top";
}
function handleOver3() {
if (document.getElementById("clicked3")) document.style.backgroundPosition="-198px top";
}
function handleOut3() {
if (document.getElementById("clicked3")) document.style.backgroundPosition="0px top";
}
</script>
【问题讨论】:
-
你在handleOver中的backgroundPosition和加载时是一样的
-
嗯,是的,我还希望将鼠标悬停在该图片上时改变它。它首先被选中,但是当我悬停其他图片时,我希望它被取消选择。一旦我再次将鼠标悬停在它上面,我希望它再次被选中
-
你能提供与问题相关的html吗?
-
也使用类:第一张图片使用第一类,第二张图片使用第二类。悬停时,检查它是哪个类,然后切换到另一个类。如果你这样做,每次你将鼠标悬停在图像上,它仍然是一样的
-
当我将 onmouseover 和 onmouseout 事件放在我的 html 中时,它工作得非常好,但我希望它完全是 javascript。
标签: javascript css onmouseover background-position onmouseout