关于div悬浮框 div处在一个初始位置,滚动条下拉,div的上端与浏览器接触,然后一直处于与浏览器接触状态,随页面而滚动。滚动条上拉到顶端,div回到初始位置。怎么做,哥哥们,网上资料不少,但是没有这个类型的。这个div悬浮框还要判断是否与浏览器接触,接触了再随浏览器移动,没接触不移动。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主 这个意思?<!doctype html><html> <head> <meta charset="gb2312" /> <title>Test</title> <style> body { height:2000px; } #test { width:100px; height:100px; position:absolute; background:#ddd; } </style> <script> function $(o){return document.getElementById(o)} window.onload = function(){ var obj = $('test'); var objTop = obj.style.top; window.onscroll = function(){ var iTop = document.documentElement.scrollTop; //alert(objTop) obj.style.top = !iTop ? objTop : iTop+'px'; } } </script> </head> <body> <div id="test" style="top:300px; right:10px;"></div> </body></html> 如何用js控制标签隐藏和显示? 发个自己写的小插件,给做企业网站的朋友 JS 如何获取对象的名称 麻烦大家帮我看看这段脚本哪写错了,该怎么改 高手:如何屏蔽关闭ie的叉?如何在关闭ie前弹出对话框,又不让在网页上做的刷新按钮刷新时候不要弹出来! 怎样实现上传一个图片(同时提交表单) 弱弱的问:用JavaScript怎样将字符串和数字组合? 网页对话框中的页面如何在对话框中刷新? js判断img图片有没有加载 padding-left:100% 它参照的单位是多少 求助 Socket 这个JS代码如何转义?
<html>
<head>
<meta charset="gb2312" />
<title>Test</title>
<style>
body { height:2000px; }
#test { width:100px; height:100px; position:absolute; background:#ddd; }
</style>
<script>
function $(o){return document.getElementById(o)}
window.onload = function(){
var obj = $('test');
var objTop = obj.style.top;
window.onscroll = function(){
var iTop = document.documentElement.scrollTop;
//alert(objTop)
obj.style.top = !iTop ? objTop : iTop+'px';
}
}
</script>
</head>
<body>
<div id="test" style="top:300px; right:10px;"></div>
</body>
</html>