实现滚动到一定位置,导航栏固定到顶部且有动画

这个动画是用透明度做的,欢迎小伙伴们交流其他的做法哟
直接上代码,
但是感觉这个透明度变化还是有点不舒服,欢迎老哥们指点。
别忘了引用jq文件哦~~~~

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			
			*{
				margin: 0;
				padding: 0;	
			}
			
			.header{
					width: 100%;
					height: 220px;
					background: lightblue;
					color: yellow;
					font-weight: bold;
					font-size: 25px;
					text-align: center;
					line-height: 220px;
				}
			
			.nav{
					width: 100%;
					height: 80px;
					background: green;
					color: greenyellow;
					font-weight: bold;
					font-size: 25px;
					text-align: center;
					line-height: 80px;
				}
		
			.content{
					width: 100%;
					height: 1200px;
					background: yellow;
					color: blueviolet;
					font-weight: bold;
					font-size: 25px;
					text-align: center;
					line-height: 1200px;
				}
			
			.footer{
					width: 100%;
					height: 600px;
					background: gray;
					color: red;
					font-weight: bold;
					font-size: 25px;
					text-align: center;
					line-height: 600px;
				}
			
			.fixed{
				z-index: 2000;
				top: 0;
				left: 0;
				position: fixed;
				/*动画保留最后一次执行状态*/
				animation: mymove 3s ease-in-out 0s 1 alternate forwards;
			}
			
			@keyframes mymove{
				from{opacity: 1;}
				to{opacity: 0.5;}
			}
			
		</style>
	</head>
	<body>
		<div class="header">头部</div>
		<div class="nav">列表</div>
		<div class="content">内容</div>
		<div class="footer">尾部</div>
		
		<script src="js/jquery1.7.js"></script>
		<script>
			$(function(){
				
				$(window).scroll(function(){
					
					var height = $(window).scrollTop();
					
					console.log(height);
				
						if (height	>400) {
							$(".nav").addClass("fixed");
						
						}else{
							$(".nav").removeClass("fixed");

						}
				})
			})
		</script>
	</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值