<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var Atop=0;
function inix(){
Atop=document.getElementByID("Layer1").style.pixelTop;
}
function move(){
document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
}
window.onscroll=move;
</script>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:48px;
top:49px;
width:82px;
height:82px;
z-index:1;
}
-->
</style>
</head><body onload="inix()">
<div id="Layer1"><img src="images/float_advclose1.gif" width="80" height="80" /></div>
<table width="200" border="1" align="center">
<tr>
<td><img src="images/xiaojie1.jpg" width="768" height="1113" /></td>
</tr>
</table>
</body>
</html>
一直不浮动 找不出原因 大家帮忙指点下
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var Atop=0;
function inix(){
Atop=document.getElementByID("Layer1").style.pixelTop;
}
function move(){
document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
}
window.onscroll=move;
</script>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:48px;
top:49px;
width:82px;
height:82px;
z-index:1;
}
-->
</style>
</head><body onload="inix()">
<div id="Layer1"><img src="images/float_advclose1.gif" width="80" height="80" /></div>
<table width="200" border="1" align="center">
<tr>
<td><img src="images/xiaojie1.jpg" width="768" height="1113" /></td>
</tr>
</table>
</body>
</html>
一直不浮动 找不出原因 大家帮忙指点下
和<html>里的xmlns="http://www.w3.org/1999/xhtml"
去掉
1 Atop=document.getElementByID("Layer1").style.pixelTop;
应该写为
Atop=document.getElementById("Layer1").style.pixelTop; 2 document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
应该写为
document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrollTop;*大小写要注意哦关于窗口不能浮动的问题,我不大懂。
我试了用LZ的方法,window.onscroll=move,似乎没执行。
继续关注....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
var Atop = 0;
function inix(){
Atop = document.getElementById("Layer1").style.pixelTop;
}
function move(){
document.getElementById("Layer1").style.pixelTop = Atop + document.documentElement.scrollTop;
}
window.onscroll = move;
</script>
<style type="text/css">
<!-- #Layer1 {
position: absolute;
left: 48px;
top: 49px;
width: 82px;
height: 82px;
z-index: 1;
}
-->
</style>
</head>
<body onload="inix();">
<div id="Layer1">
<img src="images/float_advclose1.gif" width="80" height="80" />
</div>
<table width="200" border="1" align="center">
<tr>
<td>
<img src="images/xiaojie1.jpg" width="768" height="1113" />
</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
var Atop = 0;
function inix(){
Atop = findPos(document.getElementById("Layer1"))[1];
}
function move(){
document.getElementById("Layer1").style.pixelTop = Atop + document.documentElement.scrollTop;
}
function findPos(obj){
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
while (obj = obj.offsetParent);
}
return [curleft, curtop];
}
window.onscroll = move;
</script>
<style type="text/css">
<!-- #Layer1 {
position: absolute;
left: 48px;
top: 49px;
width: 82px;
height: 82px;
z-index: 1;
}
-->
</style>
</head>
<body onload="inix();">
<div id="Layer1">
<img src="images/float_advclose1.gif" width="80" height="80" />
</div>
<table width="200" border="1" align="center">
<tr>
<td>
<img src="images/xiaojie1.jpg" width="768" height="1113" />
</td>
</tr>
</table>
</body>
</html>
我改了一处的代码。
将原先的代码
document.getElementByID("Layer1").style.pixelTop=Atop+document.body.scrolltop;
改为
document.getElementById("Layer1").style.pixelTop=Atop+document.documentElement.scrollTop; 还有一个问题,就是
Atop的值为何总是0...
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
while (obj = obj.offsetParent);
}
return [curleft, curtop];
}
我自己出现过这种错误..还有几是 不稳定一样 虽然滚动了 但是 又跳到上面去了 就是top=0 了郁闷 但是同样的代码别人copy了运行又可以 .......是运气吗..
<script>
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 50
var obj=document.getElementById('ad')
function floatAD() {
var L=T=0
var R= document.body.clientWidth-obj.offsetWidth
var B = document.body.clientHeight-obj.offsetHeight
obj.style.left = x + document.body.scrollLeft
obj.style.top = y + document.body.scrollTop
x = x + step*(xin?1:-1)
if (x < L) { xin = true; x = L}
if (x > R){ xin = false; x = R}
y = y + step*(yin?1:-1)
if (y < T) { yin = true; y = T }
if (y > B) { yin = false; y = B }
}
var itl= setInterval('floatAD()', delay)
obj.onmouseover=function(){clearInterval(itl)}
obj.onmouseout=function(){itl=setInterval('floatAD()', delay)}
</script><script language=javascript>
function CloseAD4()
{
document.getElementById('ad').style.visibility = "hidden";
}
</script>
和 <html>里的xmlns="http://www.w3.org/1999/xhtml"
去掉 再把你的大小写写好 像四楼说的那几个 还有就是 把样式写在层里面就好了
把
position:absolute;
left:48px;
top:49px;
width:82px;
height:82px;
z-index:1; 剪掉 放到行内
结果就是
<div id="Layer1"
style="position:absolute;
left:48px;
top:49px;
width:82px;
height:82px;
z-index:1"> <img src="images/float_advclose1.gif" width="80" height="80" /> </div>