华为官网商品过渡效果:
鼠标移动到商品内,图片缩放、背景渐变色、了解更多上浮
且将鼠标放到了解更多上,红色右箭头会向右移动
案例模仿效果:
用到的字体图标:iconfont-阿里巴巴矢量图标库
代码:
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./iconfont/iconfont.css">
<link rel="stylesheet" href="hw.css">
</head>
<body>
<div class="pic">
<img src="HUAWEI P50E.jpg" alt="HUAWEI P50E">
<a href="#" class="mask"></a>
<a href="#" class="more">
<span>产品</span>
<h2>HUAWEI P50E</h2>
<p>万象新生</p>
<div>
<span>了解更多</span>
<i class="iconfont icon-youjiantou"></i>
</div>
</a>
</a>
</body>
</html>
css:
* {
margin: 0;
padding: 0;
font-size: 16px;
color: #fff;
box-sizing: border-box;
}
i {
font-style: normal;
}
a {
/* 去除a下划线 */
text-decoration: none;
}
.pic {
position: relative;
margin: 100px auto;
width: 446px;
height: 445px;
/* 超出的范围不可见 */
overflow: hidden;
/* 设置pic里的mask遮罩显示所需要的时间 */
transition: opacity .7s;
/* cursor: pointer; */
}
img {
width: 446px;
height: 445px;
/* 设置img缩放需要的时间 */
transition: transform .7s;
}
.pic:hover img{
/* 缩放 */
transform: scale(105%);
}
.pic:hover .mask{
/* 显示遮罩 */
/* opacity: 1; */
background-image: linear-gradient(
transparent,
rgba(0,0,0,.6)
);
}
.mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
background-image: linear-gradient(
transparent,
rgba(0,0,0,.3)
);
/* 默认不可见,当鼠标移动到图片上显示 */
/* opacity: 0; */
}
.pic:hover .more {
bottom: 0;
display: block;
}
.more {
position: absolute;
bottom: -50px;
left: 0;
padding: 25px 30px;
width: 100%;
transition: all .5s;
}
.more span:nth-child(1) {
font-size: 18px;
}
.more h2 {
margin: 8px 0;
font-size: 24px;
}
.more p {
margin-bottom: 30px;
font-size: 18px;
color: #cbcbcb;
}
.more div {
font-size: 18px;
color: #fff;
}
/* 字体图标 */
.more div i {
content: '\e629';
color: #c7000b;
font-weight: 700;
font-family: 'iconfont';
transition: all .2s;
}
.more div:hover i {
content: '\e629';
color: #a2131e;
font-family: 'iconfont';
font-weight: 700;
margin-left: 4px;
}