javascript 浮动广告 代码 类

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
 
< HEAD >
  
< TITLE >  javascript 浮动广告代码  </ TITLE >
 
</ HEAD >

 
< BODY >
 
<!--   position:absolute;  -->
< div  id ='sign1'  style ='cursor:hand;' >
< href ='http://www.163.com/' >< img  border =0  src ="http://images.163.com/homepage/logo.gif"   /></ a >
</ div >

< div  id ='sign2' >
< href ='http://www.fleaphp.org/' >< img  border =0  src ="http://www.fleaphp.org/files/fleaphp_logo.gif"   /></ a >
</ div >

< div  id ='sign3'  >
< href ='http://www.ynjob.net/' >< img  border =0  src ="http://ynjob.net/images/sm_logo.gif"   />
</ div >

< script  language ="JavaScript"   >
//使用方法
var tmpObj1=new GggMoveSign("sign1");    // 设定要移动的对象 
tmpObj1.MoveTo(150,50);            //从哪里开始移动
tmpObj1.Run(50,10);                //    tmpObj1.Run(每隔多少时间移动一次,每次移动几个像素);


var tmpObj2=new GggMoveSign("sign2");
tmpObj2.MoveTo(
300,350);            //从哪里开始移动
tmpObj2.Run(300);

var tmpObj3=new GggMoveSign("sign3");
tmpObj3.Run();

/**
 *  javascript GggMoveSign 移动广告类 注意移动的轨迹可以根据自己的需要 修改 GetNextY GetNextX 方法
 *  signId    要移动的对象 
 *  2007-7-5  GGG  mail:gggxin@zj.com QQ:632519  http://www.zggo.com
 
*/

function GggMoveSign(signId)
{
    eval(
"this.mSignid="+signId);    //这样就充许传递字符窜为对象
    this.mStepMove    = 10;            //每次移动几个像素
    this.mDelay        = 100;            //每隔多少时间移动一次 

    
this.mMoveable    = true;            //是否能移到的标记
    this.mTimer;                    //时钟

    
//可以浮动的边界
    this.mMaxX;
    
this.mMaxY;
    
this.mMinX;
    
this.mMinY; 

    
//当前对象的座标位置
    this.mCurrX    = 0;
    
this.mCurrY    = 0

    
//移动的方向
    this.mMoveDirectionX    = 1;    //1 表示从左到右 增加 0 减少
    this.mMoveDirectionY    = 1;    //1 从上到向 

    
//设制能否移动状态
    this.SetMoveable = function(isMoveable)
    
{
        
this.mMoveable    = isMoveable;
        
if(isMoveable)
            
this.Run()
        
else
            clearTimeout(
this.mTimer)
    }


    
//得到当前要移动对像的宽
    this.GetSignWidth = function()
    
{
        
return (this.mSignid).offsetWidth; 
    }


    
//当前要移动对像的高
    this.GetSignHeight = function()
    
{
        
return (this.mSignid).offsetHeight; 
    }


    
/**
     *  移到指定位置 x y
     
*/

    
this.MoveTo = function(x,y)
    
{
        
//保存当前座标
        this.mCurrX    = x;
        
this.mCurrY    = y; 
        (
this.mSignid).style.left    = this.mCurrX + document.body.scrollLeft;
        (
this.mSignid).style.top    = this.mCurrY + document.body.scrollTop;
    }



/**
 *  得到对像移动到下一个 X 座标 的位置
 
*/

    
this.GetNextX = function()
    
{
        
//当前对像所在位置
        var curr_pos    = this.mCurrX;
        
//移动后如果超出最大宽度 弹回 返回

        
if(this.mMoveDirectionX == 1)
        
{
            curr_pos 
+=this.mStepMove;
        }

        
else
            curr_pos 
-=this.mStepMove;

        
//移动后如果超出最大宽度 弹回 返回
        if(curr_pos  > this.mMaxX )    //碰到右边界 弹回
        {
            
this.mMoveDirectionX    = 0;
        }

        
else if(curr_pos < this.mMinX )            //碰到左边界 弹回
            this.mMoveDirectionX    = 1;

        
return  curr_pos;
    }



    
/**
     *  得到对像移动到下一个 y 座标 的位置
     
*/

    
this.GetNextY = function()
    
{
        
//当前对像所在位置
        var curr_pos    = this.mCurrY ;

        
if(this.mMoveDirectionY == 1)
        
{
            curr_pos 
+=this.mStepMove;
        }

        
else
            curr_pos 
-=this.mStepMove;

        
//移动后如果超出最大宽度 弹回 返回
        if(curr_pos  > this.mMaxY)    //碰到下边界 弹回
        {
            
this.mMoveDirectionY    = 0;
        }

        
else if(curr_pos <  this.mMinY)            //碰到上边界 弹回
            this.mMoveDirectionY    = 1;

        
return  curr_pos;
    }


    
/**
     *  自动移动
     
*/

    
this.Move = function()
    
{
        
if(this.mMoveable)
            
this.MoveTo(this.GetNextX(),this.GetNextY());
    }


    
/**
     *  timeDelay    每隔多少时间移动一次
     *  stepMove    每次移动几个像素
     
*/

    
this.Run = function(timeDelay,stepMove)
    
{
        
var obj_name = this;

        
if(timeDelay)
            
this.mDelay    = timeDelay;

        
if(stepMove)
            
this.mStepMove    = stepMove;


        
with(this.mSignid)
        
{
            style.position    
= "absolute";    //设定为绝对定位
            visibility    = "visible";
            onmouseover    
= function () {obj_name.SetMoveable(false)}//鼠标经过,停止滚动
            onmouseout    = function () {obj_name.SetMoveable(true) }//鼠标离开,开始滚动
        }


        
//设定边界 
        this.mMaxX    = document.body.clientWidth  - this.GetSignWidth() - 10 ;
        
this.mMaxY    = document.body.clientHeight  - this.GetSignHeight() - 10 ; 
        
this.mMinX    = 10;
        
this.mMinY    = 10;


        
this.mTimer = setInterval(function () {obj_name.Move();}this.mDelay);        //开启定时器
    }

}

</ script >


 
</ BODY >
</ HTML >

下载
http://dl2.csdn.net/down4/20070705/05131644390.html
http://dl2.csdn.net/down4/20070705/05131720132.js

如果 document.body.scrollTop 不起作用 请用 document.documentElement.scrollTop 来代替 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值