简体   繁体   English

HTML / Jquery:即使z-index设置为最高,div也不会检测到悬停?

[英]HTML/Jquery: div not detecting hover even when z-index set to highest?

I am having an odd problem - have a div within wrapper assigned to a class name here: 我有一个奇怪的问题 - 在这里给一个类名分配包装器中的div:

echo '<div class="about">Z&S</div>';

In my stylesheet, the wrapper around this div has a z-index of -1 but I have given .about a z-index of 5 (so it will definitely be above all other elements). 在我的样式表中,这个div周围的包装器的z-index为-1但是我给出了一个z-index为5(所以它肯定会高于所有其他元素)。 I have even tried deleting the z index given to my wrapper but my problem still persists. 我甚至尝试删除给我的包装器的z索引,但我的问题仍然存在。

My problem is that I am trying to change content of div on hover using this script: 我的问题是我试图使用此脚本在悬停时更改div的内容:

$(document).ready(function() {
    console.log("LOADED SCRIPT.JS");

    //Change creds text
    $(".about").hover(
        function() // on mouseover
        {


    console.log("RAN IT");
            $(this).text("This is the new html");
        }, 

        function() // on mouseout
        {
            $(this).text("Z&Snnn");

        });

});

I know this is executing because "LOADED" is printed to console. 我知道这是执行因为“LOADED”打印到控制台。 However I cannot change the div's text because .about is not detecting hover. 但是我无法更改div的文本,因为.about没有检测到悬停。 The log within the hover function is not printed. 不会打印悬停功能中的日志。

I've never had this before - why won't my div detect hover? 我之前从未见过这个 - 为什么我的div不能检测到悬停?

EDIT- I have tried: 编辑 - 我试过:

$(".about").on("mouseover", function(){
 console.log("HELLO");
 })

and

$(document).on("mouseover",".about", function(){
            console.log("RAN IT");
            $(this).text("This is the new html");
});

Nothing is printed when I hover over it. 当我将鼠标悬停在它上面时,什么都没打印出来。 I have also deleted the z index on my wrapper if that should affect anything 我还删除了我的包装器上的z索引,如果它应该影响任何东西

您可以尝试$(".about").on("mouseover", function(){})也许,但我想如果你的包装器有-1 z-index ,不管你的孩子z-index是什么,任何兄弟姐妹使用z-index > -1的包装器的元素仍将覆盖你的包装器的子节点(我想,对不起,如果我错了)

z-index仅与position属性一起使用。使用hover()方法,将两个参数作为mouseentermouseout函数传递。我尝试使用悬停,如果这对你有帮助,那么在这个链接上检查它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM