分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

js应用例子——滚动固定

发布时间:2023-09-06 01:32责任编辑:沈小雨关键词:js

<style type="text/css">

*{ margin:0px auto; padding:0px;}
#wai{ width:100%; height:3000px;}
#head{ width:100%; height:200px; background-color:#C30;}
#dhl{ width:100%; height:150px; background-color:#00C;}
#neirong{ width:100%; height:2000px;}
.a{ width:100px; height:200px; background-color:#0FF; margin-top:30px;}
</style>

<div id="wai">
<div id="head"></div>
???<div id="dhl"></div>
???<div id="neirong">
???<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???????<div class="a"></div>
???</div>
</div>

<script>

//这里用到的window.onscroll 是网页滚动监听, scrollY是网页下拉是滚动的长度,用alert输出是不带px的数值;


window.onscroll = function(){
if(window.scrollY>200){
  var dhl = document.getElementById("dhl");
  dhl.style.position = "fixed";
  dhl.style.top = "0px";
  }else{
  dhl.style.position="";
}
}
</script>

js应用例子——滚动固定

原文地址:http://www.cnblogs.com/forqiwen/p/8098065.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved