var adLeftSrc = "http://www.img1.zj.com/life/060403.gif"
var adLeftFlash = ""
var adLeftHref = ""
var adLeftWidth = 80
var adLeftHeight = 80
var adRightSrc = "http://www.img1.zj.com/life/060403.gif"
// var adRightSrc = "http://adimg.163.com/channel1/bbn_news8080_1229.swf"
var adRightFlash = ""
var adRightHref = "http://web.zj.com/ad/lsd/"
var adRightWidth = 80
var adRightHeight = 80
var marginTop = 200 //在这里更改距离浏览器底端的高度
var marginLeft = 20//在这里更改距离浏览器右端的高度
var navUserAgent = navigator.userAgent
function load(){
judge();
move();
}
function move() {
judge();
setTimeout("move();",80)
}
function judge(){
if (navUserAgent.indexOf("Firefox") >= 0 || navUserAgent.indexOf("Opera") >= 0) {
if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adLeftHeight - marginTop + 'px';}
if (adRightSrc != "") {
document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - adRightHeight - marginTop + 'px';
document.getElementById("adRightFloat").style.left = ((document.body.clientWidth > document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
}
}
else{
if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adLeftHeight - marginTop + 'px';}
if (adRightSrc != "") {
document.getElementById("adRightFloat").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - adRightHeight - marginTop + 'px';
document.getElementById("adRightFloat").style.left = ((document.documentElement.clientWidth == 0)?document.body.clientWidth:document.documentElement.clientWidth) - adRightWidth - marginLeft + 'px';
}
}
if (adLeftSrc != "") {document.getElementById("adLeftFloat").style.left = marginLeft + 'px';}
}
if (adLeftSrc != "") {
if (adLeftFlash == "flash") {
document.write("<div id=\"adLefttFloat\" style=\"position: absolute;width:" + adLeftWidth + ";height:100px; font-size:12px;\"><img src=\"http://www.zj.com/ad/cha.gif\" width=\"12\" border=\"0\" height=\"12\" onMousedown=\"javascript:close_float_left();void(0);\";>");
document.write("<div id=\"Float\" style=\"width:" + adLeftWidth + ";\"><a href=\"" + adLeftHref +"\"><embed src=\"" + adLeftSrc + "\" quality=\"high\" width=\"" + adLeftWidth + "\" height=\"" + adLeftHeight + "\" type=\"application/x-shockwave-flash\"></embed></a></div>");
document.write("</div>");
}
else{
document.write("<div id=\"adLeftFloat\" style=\"position: absolute;width:" + adLeftWidth + ";height:100px; font-size:12px;\"><img src=\"http://www.zj.com/ad/cha.gif\" width=\"12\" border=\"0\" height=\"12\" onMousedown=\"javascript:close_float_left();void(0);\";>");
document.write("<div id=\"Float\" style=\"width:" + adLeftWidth + ";\"><a href=\"" + adLeftHref +"\" target=_blank><img src=\"" + adLeftSrc + "\" width=\"" + adLeftWidth + "\" height=\"" + adLeftHeight + "\" border=\"0\" \></a></div>");
document.write("</div>");
}
}
if (adRightSrc != "") {
if (adRightFlash == "flash") {
document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + adRightWidth + ";height:100px; font-size:12px;text-align:right;\"><img src=\"http://www.zj.com/ad/cha.gif\" width=\"12\" border=\"0\" height=\"12\" onMousedown=\"javascript:close_float_right();void(0);\";>");
document.write("<div id=\"Float\" style=\"position: absolute;width:" + adRightWidth + ";\"><a href=\"" + adRightHref +"\"><embed src=\"" + adRightSrc + "\" quality=\"high\" width=\"" + adLeftWidth + "\" height=\"" + adRightHeight + "\" type=\"application/x-shockwave-flash\"></a></embed></div>");
document.write("</div>");
}
else{
document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + adRightWidth + ";height:100px; font-size:12px;text-align:right;\"><img src=\"http://www.zj.com/ad/cha.gif\" width=\"12\" border=\"0\" height=\"12\" onMousedown=\"javascript:close_float_right();void(0);\";>");
document.write("<div id=\"Float\" style=\"width:" + adRightWidth + ";\"><a href=\"" + adRightHref +"\" target=_blank><img src=\"" + adRightSrc + "\" width=\"" + adLeftWidth + "\" height=\"" + adRightHeight + "\" border=\"0\" \></a></div>");
document.write("</div>");
}
}
function close_float_right(){
document.getElementById("adRightFloat").style.display="none";}
function close_float_left(){
document.getElementById("adLeftFloat").style.display="none";}
load();
解决方案 »
- javascript日历 求助各位兄弟姐妹
- 菜鸟求助关于js的问题
- 图片切换问题
- 救命啊……求最新的日历控件,急求~~~
- 当光标停在a标签的链接上,怎么在光标处显示一段文字提示?
- 实现像163那样的鼠标延迟感应特性,请教不用层,用table能怎么实现,js高手来拿分吧?
- 请教replace方法的问题
- javascript高手请进(在线等待)
- 急急急!一个弱问题!!!如何在js中实现一个拼起来的http请求?
- 关于list传值给同级div的方法(新手)
- js cookie设置,临时文件里却没有cookie!?
- onmouseover="setTimeout('showMsg(event.x,event.y)',3000)" 这句应该怎么写
有N种,你想要哪种就用哪种
<a href="http://net.nuaa.edu.cn" target="_blank">
<img src="1.gif" border="0">
</a>
</div>
<script>
//漂浮层的初始位置,分别对应层的初始X坐标和Y坐标
var x = 0,y = 0
//判断漂浮层的X坐标和Y坐标是否在在控制范围之内,xin为真时漂浮层向右移动,否则向//左;yin为真时漂浮层向下移动,否则向上
var xin = true, yin = true
var step = 1 //漂浮层移动的步长,值越大移动速度越快
var delay = 10 //漂浮层移动的时间间隔,单位为毫秒,值越小移动速度越快 //捕获id为ad的漂浮层作为漂浮目标
var obj=document.getElementById("ad") function floatAD()
{
var L=T=0 //漂浮层移动范围的左边界(L)和上边界(T)坐标
var R= document.body.clientWidth-obj.offsetWidth //漂浮层移动范围的右边界 var B = document.body.clientHeight-obj.offsetHeight //漂浮层移动范围的下边界 /*更新漂浮层的X坐标以实现X轴方向上的运动。document.body.scrollLeft
为文档区域的滚动条向右滚动的距离,以保证在滚动条右拉时漂浮层仍在可见范围内*/
obj.style.left = x + document.body.scrollLeft /*更新漂浮层的Y坐标以实现Y轴方向上的运动。document.body.scrollTop为文档区域的滚动条向下拉的距离,以保证在滚动条下拉时漂浮层仍在可见范围内*/
obj.style.top = y + document.body.scrollTop
x = x + step*(xin?1:-1)//通过判断漂浮层的范围决定层在X轴上的运动方向 if (x < L)
xin = true;
if (x > R)
xin = false;
y = y + step*(yin?1:-1) //通过判断漂浮层的范围决定层在Y轴上的运动方向 if (y < T)
yin = true;
if (y > B)
yin = false;
} //每delay秒执行一次floatAD函数
var itl= setInterval('floatAD()', delay) //鼠标移上时清除上面的间隔事件,实现漂浮层在的鼠标移上时停止运动的效果
obj.onmouseover=function()
{
clearInterval(itl)
} //鼠标移开时开始间隔事件,实现漂浮层在的鼠标移开时继续运动的效果
obj.onmouseout=function()
{
itl=setInterval('floatAD()', delay)
} </script>
<!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>
<title>AD </title>
</head>
<body>
<div style="height:2000px;">效果测试</div>
<script type="text/javascript">
var step = 1;
var speed = 100;
var collection;
function floaters_move(){
this.items = [];
this.addItem = function(id,x,y,content){
document.write('<div id='+id+' style="z-index:2; position:absolute;">'+content+'</div>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.xPos = x;
newItem.yPos = y;
newItem.xon = 0;
newItem.yon = 0;
this.items[this.items.length] = newItem;
}
this.play = function(){
collection = this.items;
setInterval('move_play()',speed);
}
}
function move_play(){
for(var i=0;i <collection.length;i++){
var followObj = collection[i].object;
var followObj_x = followObj.offsetWidth;
var followObj_y = followObj.offsetHeight;
var sLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
var sTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop);
followObj.style.left = (collection[i].xPos + sLeft)+'px';
followObj.style.top = (collection[i].yPos + sTop)+'px';
if(collection[i].xon) collection[i].xPos += step;
else collection[i].xPos -= step;
if(collection[i].yon) collection[i].yPos += step;
else collection[i].yPos -= step;
if(collection[i].xPos >= (document.documentElement.clientWidth-followObj_x)){
collection[i].xon = 0;
collection[i].xPos = document.documentElement.clientWidth-followObj_x;
}
if(collection[i].xPos < 0){
collection[i].xon = 1;
collection[i].xPos = 0;
}
if(collection[i].yPos >= (document.documentElement.clientHeight-followObj_y)){
collection[i].yon = 0;
collection[i].yPos = document.documentElement.clientHeight-followObj_y;
}
if(collection[i].yPos < 0){
collection[i].yon = 1;
collection[i].yPos = 0;
}
}
}var theFloaters_move = new floaters_move();
theFloaters_move.addItem('myad',200,100,'<a href="http://www.google.com" target=_blank><img src="ad.gif" width="200" height="300" border="0" /></a>');
theFloaters_move.play();
</script>
</body>
</html>
没装其它浏览器,也就不知道其它浏览器下如何了.不过应该是兼容的.
<a href="http://www.paypal.com/cgi-bin/webscr?cmd=_pbp-info-outside" target="_blank"><img src="images/paypal.gif" alt="Buyer Protection, Please click it to view details." width="179" height="57" border="0"></a>
</div>
<script>
//漂浮层的初始位置,分别对应层的初始X坐标和Y坐标
var x = 0,y = 0
//判断漂浮层的X坐标和Y坐标是否在在控制范围之内,xin为真时漂浮层向右移动,否则向//左;yin为真时漂浮层向下移动,否则向上
var xin = true, yin = true
var step = 1 //漂浮层移动的步长,值越大移动速度越快
var delay = 10 //漂浮层移动的时间间隔,单位为毫秒,值越小移动速度越快 //捕获id为ad的漂浮层作为漂浮目标
var obj=document.getElementById("ad") function floatAD()
{
var L=T=0 //漂浮层移动范围的左边界(L)和上边界(T)坐标 var R= document.body.clientWidth-obj.offsetWidth //漂浮层移动范围的右边界 var B = document.body.clientHeight-obj.offsetHeight //漂浮层移动范围的下边界 /*更新漂浮层的X坐标以实现X轴方向上的运动。document.body.scrollLeft
为文档区域的滚动条向右滚动的距离,以保证在滚动条右拉时漂浮层仍在可见范围内*/
obj.style.left = x + document.body.scrollLeft /*更新漂浮层的Y坐标以实现Y轴方向上的运动。document.body.scrollTop为文档区域的滚动条向下拉的距离,以保证在滚动条下拉时漂浮层仍在可见范围内*/
obj.style.top = y + document.body.scrollTop
x = x + step*(xin?1:-1)//通过判断漂浮层的范围决定层在X轴上的运动方向 if (x < L)
xin = true;
if (x > R)
xin = true;
y = y + step*(yin?1:-1) //通过判断漂浮层的范围决定层在Y轴上的运动方向 if (y < T)
yin = false;
if (y > B)
yin = false; } //每delay秒执行一次floatAD函数
var itl= setInterval('floatAD()', delay) //鼠标移上时清除上面的间隔事件,实现漂浮层在的鼠标移上时停止运动的效果
obj.onmouseover=function()
{
clearInterval(itl)
} //鼠标移开时开始间隔事件,实现漂浮层在的鼠标移开时继续运动的效果
obj.onmouseout=function()
{
itl=setInterval('floatAD()', delay)
} </script>