8.鼠标滑动变大变小效果

有时候我们在前端需要一种效果就是鼠标滑入然后商品变大或者变小的效果。显示为选中的效果在电商里面使用很频繁代码如下

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		*{
			margin:0px;
			padding:0px;
		}
		img {
			width:232px;
			height:174px;
			position:absolute;
			top:50%;
			left:50%;
			transform:translate(-50%,-50%);
			transition:0.1s;
			/*后面五行是规定写法意思是在居中显示最后一句是动画效果*/
		}
		.imgbox {
			width:232px;
			height:174px;
			position:relative;
		}
		.imgbox:hover {
			width:220px;
			height:162px;
		}
	</style>
</head>
<body>
		<div>
			<!-- 添加imgbox的目的是因为在变动的适合会引起布局的改变所以需要给一个固定的盒子大小 -->
			<div class="imgbox"><img src="22.jpg" alt=""></div>
			
		</div>
</body>
</html>

posted on 2023-01-05 10:35  孤灯引路人  阅读(92)  评论(0编辑  收藏  举报

导航