Html+Css+Js图片阴影动画效果(完整代码+详解)

一,问题描述


当鼠标移动到图片上时,图片下方会有透明的阴影和文字的动画效果,移出图片时同样有退出的动画效果,动画的移入和移出,动作是缓慢的。

二,效果预览


在这里插入图片描述

三,用到的主要事件


  • onmourseover:鼠标移入图片时,略过图片触发。
  • onmourseout:鼠标移出图片时触发。
  • window.setInterval():定时器,每隔多少时间对指定方法 进行调用,主要用于动画的过度效果。

四,详细代码

  • 代码结构
    在这里插入图片描述
  • Html代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<link rel="stylesheet" type="text/css" href="../css/shadow.css"/>
	<script type="text/javascript" src="../js/shadow.js" ></script>
	<body>
		<ul id="nav">
			<li><img src="../../2019-07-30-广告/images/me_background.jpg"/></li>
			<li>阴影</li>
			<li>男孩子一定要努力呀</li>
		</ul>
	</body>
</html>

  • Css代码
*{
	padding: 0px;
	margin: 0px;
}
body{
	margin: 0 auto;
	/*text-align: center;*/
}
#nav{
	width: 400px;
	margin: 0 auto;
	text-align: center;
	position: relative;
	overflow: hidden;
}
#nav img{
	width: 400px;
}
#nav li{
	list-style: none;
	width: 100%;
}
#nav li:nth-child(2){
	opacity: .4;
	text-indent: -9999px;
	background-color: gray;
}
#nav li:nth-child(2),#nav li:nth-child(3)
{
	height: 40px;
	line-height: 40px;
	font-size: 26px;
	color: darkorange;
	position: absolute;
	left: 0px;
	bottom: -40px;
}

  • JS代码
*{
	padding: 0px;
	margin: 0px;
}
body{
	margin: 0 auto;
	/*text-align: center;*/
}
#nav{
	width: 400px;
	margin: 0 auto;
	text-align: center;
	position: relative;
	overflow: hidden;
}
#nav img{
	width: 400px;
}
#nav li{
	list-style: none;
	width: 100%;
}
#nav li:nth-child(2){
	opacity: .4;
	text-indent: -9999px;
	background-color: gray;
}
#nav li:nth-child(2),#nav li:nth-child(3)
{
	height: 40px;
	line-height: 40px;
	font-size: 26px;
	color: darkorange;
	position: absolute;
	left: 0px;
	bottom: -40px;
}

五,效果演示

在这里插入图片描述

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值