有趣的鼠标悬浮模糊流体字效果

311 阅读2分钟



<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="style.css">
		<title>有趣的鼠标悬浮模糊效果</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			
			.container {
				margin: 50px auto;
				width: 400px;
				height: 300px;
				position: relative;
			}
			
			.container:hover .box {
				opacity: 1;
			}
			
			.container:hover .title {
				opacity: 1;
				transform: translate(0);
			}
			
			.container:hover .img {
				filter: blur(2px);
				-webkit-filter: blur(2px);
				-moz-filter: blur(2px);
				-ms-filter: blur(2px);
			}
			
			.container:hover .box::before {
				height: 100%;
				top: 0;
			}
			
			.container:hover .box::after {
				width: 100%;
				left: 0;
			}
			
			.box-wrapper {
				position: absolute;
				text-align: center;
				width: 100%;
				height: 100%;
				padding: 30px;
				z-index: 99;
			}
			
			.box {
				position: relative;
				width: 100%;
				height: 100%;
				padding-top: 80px;
				opacity: 0;
				transition: opacity .8s;
			}
			
			.box::before {
				content: '';
				border: 3px solid #fff;
				border-width: 0 3px;
				position: absolute;
				width: 100%;
				height: 0;
				top: 50%;
				left: 0;
				box-sizing: border-box;
				transition: all .8s;
			}
			
			.box::after {
				content: '';
				border: 3px solid #fff;
				border-width: 3px 0;
				position: absolute;
				width: 0;
				height: 100%;
				top: 0;
				left: 50%;
				box-sizing: border-box;
				transition: all .8s;
			}
			
			.title {
				background-image: -webkit-linear-gradient(left, #D81159, #E53A40 10%, #FFBC42 20%, #75D701 30%, #30A9DE 40%, #D81159 50%, #E53A40 60%, #FFBC42 70%, #75D701 80%, #30A9DE 90%, #D81159);
				color: transparent;
				-webkit-background-clip: text;
				background-size: 200%;
				transform: translate(0, 20px);
				animation: flowlight 5s linear infinite;
				transition: transform .8s, opacity .8s;
			}
			
			@keyframes flowlight {
				0% {
					background-position: 0 0;
				}
				100% {
					background-position: -100% 0;
				}
			}
			
			@-webkit-keyframes flowlight {
				0% {
					background-position: 0 0;
				}
				100% {
					background-position: -100% 0;
				}
			}
			
			@-moz-keyframes flowlight {
				0% {
					background-position: 0 0;
				}
				100% {
					background-position: -100% 0;
				}
			}
			
			@-o-keyframes flowlight {
				0% {
					background-position: 0 0;
				}
				100% {
					background-position: -100% 0;
				}
			}
		</style>
	</head>

	<body>
		<div class="container">
			<div class="box-wrapper">
				<div class="box">
					<h1 class="title">HTML5、CSS3、ES6</h1>
				</div>
			</div>

			<img class="img" src="" alt="404">
		</div>
	</body>

</html>