javascript - 当我悬停img标签以在他下方显示文本时如何制作动画
问题描述
当我悬停img标签以在他下方显示文本时,我需要制作动画(必须是动画显示文本,缓慢)但这还不是全部它还必须在文本显示时向下移动其他内容并在文本消失时返回(当不是徘徊)。非常重要的显示文本必须是动画并返回。我不在乎它是否适用于 jq 或 css 或两者都需要工作。我是初学者,所以也许很明显我只是看不到它。
HTML:
<div class="first-block"></div>
<div class="secend-block">
<div class="box">
<img src="/Test/beach.jpg" alt="beach" width="200px" height="200px">
<p>asdasdasssssssssssssssssssssss
asdddddddddddddddddddddd
asdaaaadsssssssssssadsadsdasd
adsssssssssssssssssadsadsadsa
</p>
</div>
</div>
<div class="third-block">
<h1>some content</h1>
<h1>some content</h1>
<h1>some content</h1>
<h1>some content</h1>
</div>
CSS:
.first-block{
width: 99%;
height: 100px;
background: #f10000;
}
.secend-block{
width: 99%;
height: auto;
background: #ffffff;
}
.secend-block .box{
width: 200px;
padding-top: 10px;
margin: 0px auto;
}
.secend-block .box p{
display: none;
}
.third-block{
width: 99%;
height: auto;
background: #4400ff;
}
解决方案
利用.class:hover
基本上,当.image
鼠标悬停时,我们想要改变.text
. CSS 查询.image:hover + .text
选择在.text
其前面悬停的图像的元素。
.image {
width: 250px;
}
.text {
max-height: 0px;
overflow: hidden;
transition: max-height 1s;
}
.image:hover + .text {
max-height: 32px;
}
<div class="wrapper">
<img class="image" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
<p class="text">This is some text</p>
</div>
<div class="wrapper">
<img class="image" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
<p class="text">This is some text</p>
</div>
推荐阅读
- angularjs - 无法使用 AngularJS 在 Spring Web Project 中上传文件?
- html - 自定义配置文件颜色
- sql - 汇总三张表的 SQL 查询
- c++ - NanoMsg (NNG) 和 FlatBuffers 是否适合这个项目?
- javascript - A-tag Target=".."(新窗口)如果已经打开,则不聚焦窗口
- mysql - 子查询上的 SQL RIGHT JOIN 不起作用
- listener - 两个 MQ 侦听器都在基于负载均衡器的 Websphere Application Server HADR 上执行 MDB
- encryption - Liquibase 或任何插件是否支持 SQL 插入、更新语句的数据加密?
- android - 连接均衡器和低音增强
- javascript - 为什么我收到此 POST 请求的 invalid_client ?