Jquery 淡入淡出鼠标悬停不工作

标签 jquery html css web

我试图让 div“tile_1_text”内的文本在鼠标悬停在 div“man_1”中包含的动画上时淡入,然后在鼠标离开时让图像淡出。这是一个网页设计类(class),我的教授希望我们使用 jquery 但从未在类里面教过它。我尽可能多地阅读,但我的代码无法正常工作。任何帮助,将不胜感激!

html

<body>
<div id="tile_1">
    <div id="man_1"> </div>
    <div id="man_1_arms"> </div>
</div>

<div id="tile_1_text">
    <p>This is my last piece of leather.</p>
</div>
</body>

CSS

    body {
    background-image: url(../html%20files/background_image-01.jpg);
    background-repeat: repeat;
    font-family: "quicksand", "Arial", "Times New Roman";
    top: 79px;
    }

    #tile_1 {
    position: relative;
    margin: 0 auto 50px auto;
    width: 1024px;
    height: 768px; 
    background:url(tile%201/room-01.jpg);
    }

    #man_1 {
    background: url(tile%201/man_1.png);
    position: absolute;
    top: 161px;
    left: 145px;
    width: 175px;
    height: 591px;
    background-repeat: no-repeat;
    }

    #man_1_arms {
    background: url(tile%201/Man_1_arms-01.png);
    position: absolute;
    width: 276px;
    height: 326px;
    top: 203px;
    left: 87px;
    animation: right_arm_1 3s infinite alternate; transform: rotate(0deg);
    -webkit-animation: right_arm_1 2s infinite alternate; 
    }
    @font-face {
    font-family: quicksand;
    src:url(quicksand/Quicksand-Regular.otf)
    }

    @keyframes right_arm_1 {
    from {transform: rotate(0deg);}
    to {transform: rotate(15deg);}
    }

    @-webkit-keyframes right_arm_1 {
    from {transform: rotate(0deg);}
    to {transform: rotate(15deg);}
    }

    @-moz-keyframes right_arm_1 {
    from {transform: rotate(0deg);}
    to {transform: rotate(15deg);}
    }

    #tile_1_text {
    font-family:"quicksand", "Arial", "Times New Roman"; 
    font-size:45px;
    color:rgba(150,150,150,1.0);
    text-align: center;
    position: relative;
    display: none;
    }

j查询

$(document).ready(function(){
$("#man_1").hover(function(){
        $(this).find("#tile_1_text").fadeIn(100);
}, function(){
        $(this).find("#tile_1_text").fadeOut(100)
});
   });

最佳答案

$(document).ready(function(){
$("#man_1").hover(function(){
        $(this).find("#tile_1_text").fadeIn(100);
}, function(){
        $(this).find("#tile_1_text").fadeOut(100)
});
   });

  • 作为您的代码:当悬停在“#man_1”上时,它会在“#man_1”和淡入中找到“#tile_1_text”。但是根据您的 HTML 代码,“#tile_1_text”不在“#man_1”中。
  • 你可以试试下面的代码:

$(document).ready(function(){
$("#man_1").hover(function(){
        $("#tile_1_text").fadeIn(100);
}, function(){
        $("#tile_1_text").fadeOut(100);
});
   });

关于Jquery 淡入淡出鼠标悬停不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29113284/

相关文章:

jquery - 使用 JQuery 计算隐藏表行数

javascript - 日期选择器后模糊事件

Javascript延迟后播放声音

javascript - 在 css 属性中使用 javascript 变量

javascript - 在第三方js代码中使用jquery

javascript - 让玩家在 JavaScript 中轮流玩井字游戏

jQuery 动画移动多个 div 的边距

html - 等宽 Flexbox 行,无论列数或列内容如何

javascript - 生长树/分形动画

html - 位置 :relative and left/top 的危险