您的位置:首页 > Web前端 > JavaScript

javascript 实现FLASH浮动图标广告代码

2008-04-15 09:12 701 查看
  使用 Javascript 代码,实现一个可移动的图标在网页上飘动,鼠标放在上面的时候,图标不动,移开后,图标又开始移动.

javascript 代码如下:


<script language='javascript'>




var xPos = 0;


var yPos = 0;


var step = 1;


var delay = 10;


var height = 0;


var Hoffset = 0;


var Woffset = 0;


var yon = 0;


var xon = 0;


var xon = 0;


var interval;




var img = document.getElementById('img');


img.style.top = 0;




function changePos()




...{


width = document.body.clientWidth;


height = document.body.clientHeight;


Hoffset = img.offsetHeight;


Woffset = img.offsetWidth;


img.style.left = xPos + document.body.scrollLeft;


img.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 start() ...{


img.visibility = 'visible';


interval = setInterval('changePos()', delay);


}




function mystop()




...{


clearInterval(interval)


}




start()


</script>

页面中,代码如下:


<!-- FLASH浮动图标广代码-->


<span id='img' style='position: absolute;' onmouseover='mystop()' onmouseout='start()'>


<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'


width='140' height='160'>


<param name='movie' value='http://www.myhome.com.cn/swf/sample.swf'>


<param name='quality' value='high'>


<param name="wmode" value="transparent">


<!--这里代码可使Flash背景透明 -->


<embed src='http://www.myhome.com.cn/swf/sample.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'


type='application/x-shockwave-flash' width='306' height='141'> </embed>


</object>


</span>

  原理:就是调用Macromedia的Flash组件,在Span中运行指定的SWF文件(<param name='movie' value='http://www.myhome.com.cn/swf/sample.swf'>),Javascript脚本用于控制Span的运动.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: