【前端小实战】遮罩层动画效果

一、效果展示

在这里插入图片描述

二、完整代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
		<style type="text/css">
			body {
				background-color: black;
			}
			
			.box {
				width: 250px;
				height: 300px;
				border-radius: 50%;
				border: 4px solid white;
				overflow: hidden;
				position: relative;
				box-shadow: 0 0 30px skyblue;
				display: inline-block;
				margin: 10px;
			}
			
			/* 遮罩层 */
			.box .cover {
				position: absolute;
				background-color: black;
				
				/* 遮罩层尺寸设置和box一样 */
				width: 250px;
				height: 300px;
				border-radius: 50%;
				opacity: 0;					/* 隐藏 */
				transform: scale(0);		/* 缩放效果 */
				transition: all 1s ease;	/* 所有动画1s内完成 */
				
				/* 设置文字展示 */
				font-size: 50px;
				line-height: 300px;
				text-align: center;
				font-family: "楷体";
			}
			
			/* 鼠标经过时的遮罩层 */
			.box:hover .cover {
				opacity: 0.5;
				transform: scale(1);		/* 当鼠标经过时有个从0~1的缩放效果 */
			}
			
			/* 调整路飞图片的展示 */
			.box #lufei_img {
				height: 100%;
				position: absolute;
				left: -15px;
			}
			
			/* 调整索隆图片的展示 */
			.box #suolong_img {
				height: 100%;
				position: absolute;
				left: -50px;
			}

			/* 调整娜美图片的展示 */
			.box #namei_img {
				height: 100%;
				position: absolute;
				left: -20px;
			}
			
			.box #wusupu_img {
				height: 100%;
				position: absolute;
				left: -30px;
			}
			
			.box #shanzhi_img {
				height: 100%;
				position: absolute;
				left: -20px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<img src="./img/cover_lufei.png" alt="" id="lufei_img">
			<div class="cover" style="color: red;">路飞</div>
		</div>
		
		<div class="box">
			<img src="./img/cover_suolong.png" alt="" id="suolong_img">
			<div class="cover" style="color: green;">索隆</div>
		</div>
		
		<div class="box">
			<img src="./img/cover_namei.png" alt="" id="namei_img">
			<div class="cover" style="color: orange;">娜美</div>
		</div>
		
		<div class="box">
			<img src="./img/cover_wusuopu.png" alt="" id="wusupu_img">
			<div class="cover" style="color: seagreen;">乌索普</div>
		</div>
		
		<div class="box">
			<img src="./img/cover_shanzhi.png" alt="" id="shanzhi_img">
			<div class="cover" style="color: yellow;">山治</div>
		</div>
	</body>
</html>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值