<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
body{
margin: 0;
padding: 0;
}
.div1{
width: 100%;
height: 500px;
background: #FF0000;
position: fixed;
top: 0;
left: 0;
}
.div2{
width: 100%;
margin-top: 500px;
height: 1000px;
background: #22B0FC;
position: relative;
z-index: 2;;
}
</style>
<body>
<div class="div1">1111111</div>
<div class="div2">22222222222222</div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function () {
$(window).scroll(function () {
var scrollTop=$(window).scrollTop();
//$(window).scrollTop()这个方法是当前滚动条滚动的距离
//$(window).height()获取当前窗体的高度
//$(document).height()获取当前文档的高度
$('.div2').css('top',-scrollTop);
});
});
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
body{
margin: 0;
padding: 0;
}
.clearfix:after {
content: '';
display: block;
clear: both;
}
.div1{
width: 100%;
margin: 0 auto;
height: 500px;
background: bisque;
position: fixed;
top: 0;
left: 0;
}
.div1 div{
width: 1200px;
margin: 0 auto;
height: 500px;
background: #FF0000;
}
.div2{
width: 1200px;
margin: 0 auto;
height: 1500px;
background: #22B0FC;
z-index: 20000;;
margin-top: 500px;
}
</style>
<body>
<div class="div1 clearfix">
<div>111111111111111111111111111111111111111</div>
</div>
<div class="div2">22222222222222</div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
var div2Height=Number($('.div2').offsetTop);
var clientHeight=Number($(document).clientHeight);
var totalHeight=div2Height-clientHeight;
var objOffset=$('.div2').offset().top;
var objOffsetLf=$('.div2').offset().left;
$(document).ready(function () { //本人习惯这样写了
$(window).scroll(function () {
var scrollTop=$(window).scrollTop();
var objHeight=objOffset-scrollTop;
console.log(scrollTop);
if(scrollTop>=0){
$('.div2').css({'left':objOffsetLf,'top':objHeight,'position':'absolute','margin-top':'0px'});
}else{
$('.div2').css({'position':'static','margin-top':'500px'});
}
});
});
</script>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有