<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <style type="text/css"> *{ padding: 0px; margin: 0px; } body{ height: 2500px; } #first{ position:fixed; top:300px; left:50%; margin-left: -250px; border: 2px solid red; background-color: red; width: 500px; height: 100px; } </style> <script> function first() { scrollTop = document.documentElement.scrollTop+document.body.scrollTop; height = document.getElementById("first").offsetTop; alert(scrollTop+" "+height); } function second(){ var top = 300; var jia = 5; scrollTop = document.body.scrollTop; if(scrollTop<top){ document.getElementById("first").style.top = top + jia -scrollTop; }else if(scrollTop>top){ document.getElementById("first").style.top = jia; } } </script> </head> <body onscroll="second()"> <div id="first" onclick="first()"> </div> </body> </html>
- 粉丝: 3
- 资源: 15
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助