背景图不动,元素滚动,并且滚动到某个元素是替换背景图,回来时替换回来

本文介绍了一个使用HTML、CSS和jQuery实现的动态网页布局案例,包括背景图片切换、固定定位及响应式设计等技巧。通过三个圆形元素展示了浮动布局,并在滚动到特定位置时改变背景图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<html>
<head>

</head>
<script src='jquery1.12.4.min.js'></script>
<style>
#bod{  
  
 background-color :#FFF; background-image :url(img/2.jpg) ; background-repeat :no-repeat ;background-size:100% 100%;background-position: right bottom ;background-attachment:fixed;  
  
}  
*{
margin:0;
padding:0;
}
</style>
<body >
<div id='bod'>
<img style='width:100%;height:100%;' src="img/7.jpg" alt="">
<p style='border:1px solid red;height:700px;color:#ffffff;font-size:50px;'>
zhaoyufei
</p>
<div id='div1' style='margin:0 auto;width:1024px;height:700px;'>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid red;">1</div>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid red;">2</div>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid red;">3</div>
</div>
<div id='middle' style='width:100%;height:100%;background:#ffffff;''></div>
<div style='clear:both;'></div>
<div id='div2' style='margin:0 auto;width:1024px;height:1000px;'>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid blue;">1</div>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid blue;">2</div>
<div style="float:left;text-align:center;width:250px;height:250px;border-radius:50%;border:10px solid blue;">3</div>
</div>
</div>
</body>
<script>
$(function(){
    var h3_height = $("#middle").offset().top;
    $(window).scroll(function(){
        var this_scrollTop = $(this).scrollTop();
        if(this_scrollTop>h3_height ){
          $("#bod").css({"background-image":"url(img/8.jpg)"});
        }else{
        $("#bod").css({"background-image":"url(img/2.jpg)"});
        }
    });
});
</script>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值