js 问题 如何生成右侧浮动框,然后可以导航本页面,就是说 点那个浮动框的不同按钮,可以定位到本页面的

JavaScript029

js 问题 如何生成右侧浮动框,然后可以导航本页面,就是说 点那个浮动框的不同按钮,可以定位到本页面的,第1张

你好 这个叫做 锚链接 并不是js的效果

Exp:

1、首先我们在网页body内最上面添加一个<span id="top" name="top"></span>

2、我们再到body内,需要出现点击后转到顶部位置添加,<a href="#top">回到顶部</a>

这样就可实现点击“回到顶部”即可本页内快速浏览到网页顶部位置。

希望能帮到你 谢谢

请将代码放置在<head></head>之间即可

<script language="javascript">

suspendcode="<DIV id=lovexin style='Z-INDEX: 10LEFT: 850pxPOSITION: absoluteTOP: 140pxwidth: 88pxheight: 203px'><a href='http://www.ixym.net'><img src='../20080128/er_p.jpg' width='150' height='200' border='0'></a></DIV>"

document.write(suspendcode)

lastScrollY=0

function heartBeat(){

diffY=document.body.scrollTop

percent=.1*(diffY-lastScrollY)

if(percent>0)percent=Math.ceil(percent)

else percent=Math.floor(percent)

document.all.lovexin.style.pixelTop+=percent

lastScrollY=lastScrollY+percent

}

window.setInterval("heartBeat()",1)

</script>

代码说明:

1、加到左侧的时候,把left属性改为10就好;

2、TOP是控制这个浮动广告离上边的距离,可以根据自己的实际情况进行调整;

3、这里href='http://www.ixym.net和这里img src='../20080128/er_p.jpg' 换成你想要的浮动广告的图片。其中这句src=../20080128/er_p.jpg' width='150' height='200'border='0' 中WIDTH=‘150’ height='200'是你浮动广告图片的宽和高。

<script type="text/javascript" >

var Marginleft = 0 //浮动层离浏览器右侧的距离

var MarginTop = 100 //浮动层离浏览器顶部的距离

var Width = 180 //浮动层宽度

var Heigth= 400 //浮动层高度

//设置浮动层宽、高

function Set()

{

document.getElementById("FloatDIV").style.width = Width + 'px'

document.getElementById("FloatDIV").style.height = Heigth + 'px'

}

//实时设置浮动层的位置

function Move()

{

var b_top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0

var b_width= document.body.clientWidth

document.getElementById("FloatDIV").style.top = b_top + MarginTop + 'px'

document.getElementById("FloatDIV").style.left= b_width - Width - Marginleft + 'px'

setTimeout("Move()",100)

}

Set()

Move()

</script>