几种网页飘浮代码

第一种
<!--
//图片地址
var hbcms_img_src = 'mv1.gif';
//连接的网址
var hbcms_img_url = 'http://www.cxblog.net';
//图片宽度
var hbcms_img_w = '120';
//图片高度
var hbcms_img_h = '120';
var hbcms_img_alt = '畅想博客';

document.write('<div id=dd style="Z-INDEX: 1; WIDTH: '+hbcms_img_w+'px; POSITION: absolute; HEIGHT: '+hbcms_img_h+'px"> <a href="'+hbcms_img_url+'"><img src="'+hbcms_img_src+'" width="'+hbcms_img_w+'" height="'+hbcms_img_h+'" border="0" alt="'+hbcms_img_alt+'" onMouseOver="pause_resume();" onMouseOut="pause_resume();"></a></div> ');
var xPos = 180; // 起始横向位置(从左算起,单位象素)
var yPos = document.body.clientHeight; // 页面本身高度
var step = 1;
var delay = 30; // 速度,值越大速度越慢
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
dd.style.top = yPos;
//本代码由畅想博客(http://www.cxblog.net/)整理修改
function hbcms_changePos() {
width = document.body.clientWidth; // 判断浏览器窗口的宽度
height = document.body.clientHeight; // 判断浏览器窗口的高度
Hoffset = dd.offsetHeight;
Woffset = dd.offsetWidth;
dd.style.left = xPos + document.body.scrollLeft;
dd.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}

function hbcms_start_pp() {
dd.visibility = "visible";
interval = setInterval('hbcms_changePos()', delay);
}
function pause_resume() {
if(pause) {clearInterval(interval);pause = false;}
else {interval = setInterval('hbcms_changePos()',delay);pause = true;}
}
hbcms_start_pp();

//-->


第二种
var pngbrOK=false;
var mie=false;
var aver=parseInt(navigator.appVersion.substring(0,1));
var aname=navigator.appName;
var pngmystop=0;

function pngcheckbrOK()
{if(aname.indexOf("Internet Explorer")!=-1)
{if(aver>=4) pngbrOK=navigator.javaEnabled();
mie=true;
}
if(aname.indexOf("Netscape")!=-1)  
{if(aver>=4) pngbrOK=navigator.javaEnabled();}
}
var vmin=2;
var vmax=5;
var vr=2;
var timer1;

function pngchip(chipname,width,height)
{
this.named=chipname;
this.vx=vmin+vmax*Math.random();
this.vy=vmin+vmax*Math.random();
this.w=width;
this.h=height;
this.xx=0;
this.yy=0;
this.timer1=null;
}

function pngmovechip(chipname)
{
if(pngbrOK && pngmystop==0)
{eval("pngchip="+chipname);
if(!mie)
{pageX=window.pageXOffset;
pageW=window.innerWidth;
pageY=window.pageYOffset;
pageH=window.innerHeight;
}
else
{pageX=window.document.body.scrollLeft;
pageW=window.document.body.offsetWidth-8;
pageY=window.document.body.scrollTop;
pageH=window.document.body.offsetHeight;
}
pngchip.xx=pngchip.xx+pngchip.vx;
pngchip.yy=pngchip.yy+pngchip.vy;
pngchip.vx+=vr*(Math.random()-0.5);
pngchip.vy+=vr*(Math.random()-0.5);
if(pngchip.vx>(vmax+vmin))  pngchip.vx=(vmax+vmin)*2-pngchip.vx;
if(pngchip.vx<(-vmax-vmin)) pngchip.vx=(-vmax-vmin)*2-pngchip.vx;
if(pngchip.vy>(vmax+vmin))  pngchip.vy=(vmax+vmin)*2-pngchip.vy;
if(pngchip.vy<(-vmax-vmin)) pngchip.vy=(-vmax-vmin)*2-pngchip.vy;
if(pngchip.xx<=pageX)
{pngchip.xx=pageX;
pngchip.vx=vmin+vmax*Math.random();
}
if(pngchip.xx>=pageX+pageW-pngchip.w)
{pngchip.xx=pageX+pageW-pngchip.w;
pngchip.vx=-vmin-vmax*Math.random();
}
if(pngchip.yy<=pageY)
{pngchip.yy=pageY;
pngchip.vy=vmin+vmax*Math.random();
}
if(pngchip.yy>=pageY+pageH-pngchip.h)
{pngchip.yy=pageY+pageH-pngchip.h;
pngchip.vy=-vmin-vmax*Math.random();
}
if(!mie)
{eval('document.'+pngchip.named+'.top ='+pngchip.yy);
eval('document.'+pngchip.named+'.left='+pngchip.xx);
}
else
{eval('document.all.'+pngchip.named+'.style.pixelLeft='+pngchip.xx);
eval('document.all.'+pngchip.named+'.style.pixelTop ='+pngchip.yy);
}
pngchip.timer1=setTimeout("pngmovechip('"+pngchip.named+"')",100);
}
}
function pngstop(x)
{
pngbrOK=true;
pngmystop=x;
pngmovechip("pngtome");
}
var pngtome;
var pngchip;
function pngtome()
{pngcheckbrOK();
pngtome=new pngchip("pngtome",80,80);
if(pngbrOK)
{ pngmovechip("pngtome");
}
}

ns4=(document.layers)?true:false;
ie4=(document.all)?true:false;

function pngover()
{
if(ns4){
//document.png.left=window.innerWidth/2-400;
eval('document.png.left=document.'+pngchip.named+'.left');
eval('document.png.top=document.'+pngchip.named+'.top-0');
document.png.visibility="show";
}else if(ie4)
{
//document.all.png.style.left=window.document.body.offsetWidth/2-400;
document.all.png.style.left=parseInt(document.all.pngtome.style.left);
document.all.png.style.top=parseInt(document.all.pngtome.style.top)-20;
document.all.png.style.visibility="visible";
pngstop(1);
}
}

function pngout()
{
if(ns4){
document.png.visibility="hide";
}else if(ie4)
{
document.all.png.style.visibility="hidden";
pngstop(0);
}
}

document.write("<div id='pngtome' style='position:absolute;'><a href='News_View.asp?NewsID=878' onMouseOver=pngover() onMouseOut=pngout() target='_blank'><img src=xiaokang.gif border=0 ></a>"

+" </div>");
pngtome()

以上两种存成JS格式,在需要的页面调用即可!
调用方式:<script language="JavaScript" src="mv.js"></script>


第三种
<!--图片漂浮广告代码开始-->
<div id="www_qpsh_com" style="position:absolute">
<a href="news_more.asp?lm=&lm2=51" target="_blank">
<img src="mv2.gif" border="0">
</a>
</div>
<script>
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 10
var obj=document.getElementById("www_qpsh_com")
function floatwww_qpsh_com() {
var L=T=0
//by www.1wd.cc
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("floatwww_qpsh_com()", delay)
obj.onmouseover=function(){clearInterval(itl)}
obj.onmouseout=function(){itl=setInterval("floatwww_qpsh_com()", delay)}
</script>
<!--图片漂浮广告代码结束-->


文章来自: 本站原创
引用通告地址: http://www.cxblog.net/trackback.asp?tbID=348
Tags:
相关日志:

评论: 0 | 引用: 0 | 查看次数: 5641
发表评论
昵 称:
密 码: 游客发言不需要密码.
验证码:
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 关闭 | [img]标签 关闭