前端中animation控制动画定位到动画结束,并使用js控制3s消失

  1. 代码
<!DOCTYPE html>
<html>
<head>
	<title>home</title>
	<meta charset="utf-8">
	<style type="text/css">
		.fix_tip{
			width: 500px;
			height: 48px;
			left: 50%;
			margin-left: -250px;
			font-size: 24px;
			line-height: 48px;
			position: fixed;
			background: red;
			color: white;
			text-align: center;
			z-index: 1;
			border: 1px solid red;
			animation:myfirst 3s forwards;
			-moz-animation:myfirst 3s forwards; /* Firefox */
			-webkit-animation:myfirst 3s forwards; /* Safari and Chrome */
			-o-animation:myfirst 3s forwards; /* Opera */
		}
		@keyframes myfirst{
			from{top:0px}
			to{top:100px}
		}
		/* Firefox */
		@-moz-keyframes myfirst {
			from{top:0px}
			to{top:100px}
		}
		/* Safari and Chrome */
		@-webkit-keyframes myfirst {
			from{top:0px}
			to{top:100px}
		}
		 /* Opera */
		@-o-keyframes myfirst{
			from{top:0px}
			to{top:100px}
		}
	</style>
</head>
<body>
	<div class="fix_tip" id="fix_tip">
		<!-- <b>数据格式错误,插入失败</b> -->
	</div>
	<!-- /错误提示 -->
	<script type="text/javascript">
		setTimeout("document.getElementById('fix_tip').style.display='none'",6000);
	</script>
</body>
</html>
  1. 动画结束后停止在结束位置

    网上搜到的都是设置

    animation-fill-mode: forwards;
    

    但是事实上单独这样设置是没有效果的,正确写法是

    animation:myfirst 3s forwards;
    
  2. div在3s后消失

    1. 获取控制的div
      document.getElementById('fix_tip')

    2. 设置消失
      这里是设置该div为none
      setTimeout("document.getElementById('fix_tip').style.display='none'",6000);
      我这里设置6s消失是因为我的h5动画需要执行3s。

    3. js运行说明
      一种是写成function,在body中调用;
      另一种就是我在上面所显示的,直接在body结束标签之上,body中其他内容填充完毕,再写js方法。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值