如何将鼠标悬停在容器上以显示带有Javascript的更多按钮?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将鼠标悬停在容器上以显示带有Javascript的更多按钮?相关的知识,希望对你有一定的参考价值。

我制作了一个html页面,因为当我将鼠标悬停在容器类上时,我希望显示更多阅读类,否则应该将其隐藏。

我已经尝试了很多,但是我无法弄清楚!

如果您知道,请帮我吧!

我什至可以使用JQuery

HTML代码HTML

<div class="author">
      <div class="box">
        <div class="container" id="auHov">

            <div class="logo">
              <img src="authorLogo.png" alt="Author Logo">
            </div>

            <div class="info">
              <h2><a href="#">Quic Flicks</a></h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
              tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
              quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
              consequat.</p>
             <a class="read-more" href="#" id="auBtn">Read More</a>
            </div>

        </div>
      </div>
      </div>

CSS代码CSS

.author {
    width: 100%;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.author .box {
    margin-left: 80px;
    margin-right: 80px;
}

.author .box .container {
    padding: 1em;
    width: 100%;
    height: auto;
    border-radius: 5px;;
    background: linear-gradient(45deg, #F45C43, #EB3349);
    background-size: contain;
}

.author .box .container .logo {
    padding: 8px;
    margin: 12px;
    float: left;
    display: flex;
    align-items: center;
    justify-content: center;
}
.author .box .container .logo img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 6px solid var(--light);
}

.author .box .container .info {
    float: right;
    padding: 10px;
    margin: 4px;
}

.author .box .container .info h2 {
    font-size: 26px;
    font-family: 'Lobster', cursive;
    transition: linear 0.3s;
}

.author .box .container .info h2 a {
    text-decoration: none;
    color: var(--light-primary);
    cursor: pointer;
    text-shadow: 0.1px 0.1px 2px var(--dark);
    transition: ease 0.3s;
}

.author .box .container .info h2 a:hover {
    transition: linear 0.3s;
    text-shadow: 0.8px 0.8px 3.9px var(--dark);
    color: var(--primary);
}

.author .box .container .info p {
    font-size: 20px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    line-height: 32px;
    word-spacing: 1px;
    color: var(--light-primary);
    text-shadow: 0.1px 0.1px var(--dark);
    cursor: default;
}

.author .box .container .info .read-more {
    text-decoration: none;
    float: right;
    padding: 12px;
    margin: 5px;
    text-transform: uppercase;
    font-size: 1em;
    font-family: 'Lato', sans-serif;
    font-weight: 900;
    color: var(--dark);
    background: var(--primary);
    transition: ease 0.4s;
    /* display: none; */
}

.author .box .container .info a:hover {
        background: var(--dark-primary);
        transition: linear 0.2s;
}

javascript代码JAVASCRIPT

????????

答案

a.read-more{ display: none;} .container:hover a.read-more{ display: block;}
<div class="author"> <div class="box"> <div class="container" id="auHov"> <div class="logo"> <img src="authorLogo.png" alt="Author Logo"> </div> <div class="info"> <h2><a href="#">Quic Flicks</a></h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> <a class="read-more" href="#" id="auBtn">Read More</a> </div> </div> </div> </div>
另一答案
None
另一答案

document.getElementById("info").addEventListener("mouseover", function() { document.getElementById("auBtn").style = "display: block;"; }); document.getElementById("info").addEventListener("mouseout", function() { document.getElementById("auBtn").style = "display: none;"; });
.author { width: 100%; height: auto; display: flex; align-items: center; justify-content: center; } .author .box { margin-left: 80px; margin-right: 80px; } .author .box .container { padding: 1em; width: 100%; height: auto; border-radius: 5px;; background: linear-gradient(45deg, #F45C43, #EB3349); background-size: contain; } .author .box .container .logo { padding: 8px; margin: 12px; float: left; display: flex; align-items: center; justify-content: center; } .author .box .container .logo img { width: 100px; height: 100px; border-radius: 50%; border: 6px solid var(--light); } .author .box .container .info { float: right; padding: 10px; margin: 4px; } .author .box .container .info h2 { font-size: 26px; font-family: 'Lobster', cursive; transition: linear 0.3s; } .author .box .container .info h2 a { text-decoration: none; color: var(--light-primary); cursor: pointer; text-shadow: 0.1px 0.1px 2px var(--dark); transition: ease 0.3s; } .author .box .container .info h2 a:hover { transition: linear 0.3s; text-shadow: 0.8px 0.8px 3.9px var(--dark); color: var(--primary); } .author .box .container .info p { font-size: 20px; font-family: 'Poppins', sans-serif; font-weight: 600; line-height: 32px; word-spacing: 1px; color: var(--light-primary); text-shadow: 0.1px 0.1px var(--dark); cursor: default; } .author .box .container .info .read-more { text-decoration: none; float: right; padding: 12px; margin: 5px; text-transform: uppercase; font-size: 1em; font-family: 'Lato', sans-serif; font-weight: 900; color: var(--dark); background: var(--primary); transition: ease 0.4s; /* display: none; */ } .author .box .container .info a:hover { background: var(--dark-primary); transition: linear 0.2s; }
<div class="author">
      <div class="box">
        <div class="container" id="auHov">

            <div class="logo">
              <img src="authorLogo.png" alt="Author Logo">
            </div>

            <div class="info" id="info">
              <h2><a href="#">Quic Flicks</a></h2>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
              tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
              quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
              consequat.</p>
             <a class="read-more" href="#" id="auBtn" style="display: none;" id="_id">Read More</a>
            </div>

        </div>
      </div>
      </div>

以上是关于如何将鼠标悬停在容器上以显示带有Javascript的更多按钮?的主要内容,如果未能解决你的问题,请参考以下文章

将鼠标悬停在多个内容上以展开

将鼠标悬停在图像上以显示按钮,并且在悬停在实际按钮上时不触发

将鼠标悬停在缩略图上以启动新图像;悬停结束后新图像仍然存在

悬停在 div(1) 上以显示 div(2),如果 mouseout 继续显示 div(2) x 秒

markdown 将鼠标悬停在DIV上以扩展宽度

将鼠标悬停在 iframe 上时如何显示文本