批改状态:未批改
老师批语:
页面滚动效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>jquery第一课</title>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
*{margin:0;padding:0;}
.content{
width:100%;
height: 40px;
background:rgb(160,3,162,0.3);
box-shadow: 1px 3px 7px #ccc;
line-height: 40px;
position:fixed;
}
.content_2{background:rgb(160,3,162,0.8);}
form{
width:500px;
height:25px;
position: relative;
margin: 0 auto;
}
input{
width:480px;
height: 25px;
border-radius: 20px;
border:none;
outline:none;
padding-left: 20px;
}
button{
width:70px;
height: 25px;
order: none;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
border:none;
color:#fff;
position:absolute;
right: 0;
top: 9px;
outline: none;
font-weight: bold;
background:rgba(160,3,162,0.4);
}
[placeholder]{color:rosybrown}
.pic{
width:70%;
height: 280px;
background: url("/image/1.png");
margin:0 auto;
}
.box{
width:70%;
height: 1200px;
background: #ccc;
margin:0 auto;
}
</style>
</head>
<body >
<div class="content">
<form>
<input type="text" placeholder="#请输入关键字#">
<button>全网搜</button>
</form>
</div>
<!--轮播图-->
<div class="pic"></div>
<!--页面详情-->
<div class="box"></div>
<script>
$(function(){
//scroll时间,当用户滚动指定的元素时触发
$(window).scroll(function(){
//当滚动条滚动到顶部距离页面顶部达到导航条高度的时候,滚动条隐藏
if($(window).scrollTop()>40){
$('.content').css('display','none')
}else{
$('.content').css('display','block')
}
if($(window).scrollTop()>280){
$('.content').addClass('content_2').css('display','block')
}else{
$('.content').removeClass('content_2')
}
})
})
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号