通过JS将鼠标悬停到整个div

时间:2019-01-05 08:06:20

标签: javascript html css

当我想将鼠标悬停到div时,它将悬停整个div

l尝试设置叠加层的高度,但丢失了!

<div id="Overlay" onmouseover="hoverDown()" onmouseout="hoverUp()" onload="muteOther()">

#Overlay {
    width: 100%;
    height: 100%;
    position: absolute;
    opacity: 0;
}

function hoverUp() {
    var a = document.getElementById("Overlay");

    a.style.opacity = "0";
    a.style.transition = "all 1s";

}

function hoverDown() {
    var a = document.getElementById("Overlay");
    a.style.opacity = "1";

    setTimeout(function () {
        a.style.opacity = "0";
        a.style.transition = "all 1s";
    }, 4000);

}

当l将光标移至div时,将显示其叠加层,而当其移出叠加层时则感到绝望

1 个答案:

答案 0 :(得分:0)

尝试将JavaScript包含在<script>标记内。另外,您可以在attr_for_div=func(this)等于func(this)的js中使用thisvar a=doc...