<div class="Box">
<img src="image.jpg" alt="图片" class="img">
<div class="overlay">
<p>图片标题</p>
<p>图片描述</p>
</div>
</div>
<style>
.Box {
position: relative;
width: 300px;
height: 200px;
perspective: 1000px;
overflow: hidden;
}
.img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
transition: transform .5s;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
transform: translateZ(50px);
opacity: 0;
background-color: rgba(0,.8);
transition: opacity .5s,transform .5s;
}
.overlay p {
color: #fff;
font-size: 16px;
margin: 0;
padding: 10px;
text-align: center;
}
.Box:hover .img {
transform: translateZ(-50px) rotateY(45deg);
}
.Box:hover .overlay {
transform: translateZ(0) rotateY(-45deg);
opacity: 1;
}
</style>
以上代码中,使用了class名为Box的div作为容器,设置了透视距离perspective、宽度和高度,且设置为相对定位。而.img类则是图片的class,利用absolute定位属性放在Box容器内,并设置过渡效果,当鼠标悬停在图片上时,通过transform属性实现360度旋转的动态效果。另外,overlay类是一个半透明的遮罩层,也是绝对定位的,居中放置,同时也可以通过鼠标悬停实现3D旋转效果。至于其他样式属性就不作详细解释了。
需要注意的是,这种特效除了支持一些比较新的浏览器之外,在一些老旧浏览器中可能无法正常显示。另外,在使用之前需要确保对CSS3属性了解,方便做出一些酷炫的效果。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。