shawl.qiu javascript 漂浮广告类(无错兼容多浏览器) Moving v1.0
2007-05-17 13:50
369 查看
shawl.qiu javascript 漂浮广告类(无错兼容多浏览器) Moving v1.0
说明:写这个其实不难, 不过要考虑兼容问题, 头大了好多.
特别是IE, 许多属性基本上都是摆设....
嗯, 没啥好说的.
PS: 虽然本人不喜欢这些AD相关的东西, 不过有用处的话那就不是讨厌不讨厌的问题了.
目录:
1. 类 Moving 及调用演示
shawl.qiu
2007-05-17
http://blog.csdn.net/btbtd
下载:
http://shawl.qiu.googlepages.com/shawl.qiu_js_class_moving_v1.0.7z
演示:
http://shawl.qiu.googlepages.com/moving.htm
内容:
1. 类 Moving 及调用演示
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ */
.sqMovingAd
{
border:5px solid #EEEEEE;
background-color:white;
padding:5px;
}
/* ]]> */
</style>
<script type="text/javascript">
//<![CDATA[
/*-----------------------------------------------------------------------------------*/
* shawl.qiu javascript Moving class v1.0
/*-----------------------------------------------------------------------------------*/
//---------------------------------begin class Moving()-------------------------------//
function Moving()
{ // shawl.qiu code
//------------------------------------begin public variable
//---------------begin about
this.au = {}
this.au.Subject = "shawl.qiu javascript Moving class";
this.au.Version = "v1.0";
this.au.Name = "shawl.qiu";
this.au.Email = "shawl.qiu@gmail.com";
this.au.Blog = "http://blog.csdn.net/btbtd";
this.au.CreatedDate = "2007-5-16";
this.au.Update = {};
this.au.Update["1"] = "";
//---------------end about
this.Init ={}
this.Init.Y = 50;
this.Init.X = 50;
this.Init.Width = 80;
this.Init.Height = 80;
this.Delay = 5;
this.Span = {};
this.Span.XStep = 2;
this.Span.YStep = 5;
this.Span.YStepCount = 0;
this.Main = {};
this.Main.ID = "sqMovingAd";
this.Main.ClassName = "sqMovingAd";
this.Main.InnerHtml = "hi there, test ok...";
//------------------------------------end public variable
//------------------------------------begin private variable
var Tl = this;
var pMain = null;
//------------------------------------end private variable
//------------------------------------begin public method
this.Go = fGo;
//------------------------------------end public method
//------------------------------------begin private method
function fGo()
{
var EleDiv = document.createElement("div");
var Height = 0;
var Width = 0;
with(EleDiv)
{
id = Tl.Main.ID;
className = Tl.Main.ClassName;
innerHTML = Tl.Main.InnerHtml;
style.width = Tl.Init.Width+"px";
style.height = Tl.Init.Height+"px";
style.top = Tl.Init.Y+"px";
style.left = Tl.Init.X+"px";
if(fCkBrs()==1)
{
style.position = "absolute";
}
else
{
style.position = "fixed";
}
} // end with
document.body.appendChild(EleDiv);
EleDiv = null;
pMain = document.getElementById(Tl.Main.ID);
// for opera
if(true) //fCkBrs()==2
{
var sqMoving =
setInterval
(
function()
{
var iTemp = 0;
if(fCkBrs()==2)
{
iTemp = 18;
}
else if (fCkBrs()==1)
{
iTemp = 1;
}
else
{
iTemp = 0;
}
var iTop = parseInt(pMain.style.top);
var iLeft = parseInt(pMain.style.left);
var Width = document.body.clientWidth-Tl.Init.Width-iTemp;
// begin top
if(fCkBrs()==1)
{
var ScrollTop = document.documentElement.scrollTop;
iTop = ScrollTop;
if((fGetViewPortSize()[1]-Tl.Init.Height)<Tl.Span.YStepCount)
{
Tl.Span.YStep = -Tl.Span.YStep;
}
if(Tl.Span.YStepCount<0)
{
Tl.Span.YStep = Math.abs(Tl.Span.YStep);
}
Tl.Span.YStepCount += Tl.Span.YStep;
pMain.style.top = (iTop+Tl.Span.YStepCount)+"px";
}
else
{
var Height = fGetViewPortSize()[1]-Tl.Init.Height;
if(iTop>Height)
{
Tl.Span.YStep = -Tl.Span.YStep;
}
if(iTop<0)
{
Tl.Span.YStep = Math.abs(Tl.Span.YStep);
}
pMain.style.top = (iTop+Tl.Span.YStep)+"px";
}
// end top
if(iLeft>Width)
{
Tl.Span.XStep = -Tl.Span.XStep;
}
if(iLeft<0)
{
Tl.Span.XStep = Math.abs(Tl.Span.XStep);
}
pMain.style.left = (iLeft+Tl.Span.XStep)+"px";
}
,
Tl.Delay
);
} // end if
} // end function fGo
function fCkBrs()
{// shawl.qiu script
switch (navigator.appName)
{
case 'Opera': return 2;
case 'Netscape': return 3;
default: return 1;
}
} // end function fCkBrs
function fGetViewPortSize()
{// shawl.qiu script
var myWidth = 0, myHeight = 0;
if(typeof(window.innerWidth ) == 'number' )
{//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}
else if
(
document.documentElement &&
( document.documentElement.clientWidth || document.documentElement.clientHeight )
)
{//IE 6
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
{ //IE 4
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
return [myWidth, myHeight];
} // end function fGetViewPortSize
//------------------------------------end private method
} // shawl.qiu code
//---------------------------------end class Moving()---------------------------------//
onload =
function()
{
var moving = new Moving();
moving.Go();
moving = null;
}
//]]>
</script>
</head>
<body>
<br />
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>
相关文章推荐
- [转]javascript对联广告、漂浮广告封装类,多浏览器兼容
- 右下角弹出广告 js,漂浮效果(兼容多浏览器)
- 兼容各大浏览器带关闭按钮的漂浮多组图片广告代码
- 不用js多浏览器兼容纯DIV/CSS对联漂浮广告代码
- js右下角与漂浮广告代码(兼容多浏览器)
- js右下角与漂浮广告代码(兼容多浏览器)
- 兼容各大浏览器带关闭按钮的漂浮多组图片广告代码
- 纯 CSS 弹出菜单 之 横排三级分类(兼容多个浏览器) By shawl.qiu
- javascript判断浏览器 和 完美兼容IE和chrome的对联广告。
- 右下角弹出广告 js,漂浮效果(兼容多浏览器)
- 不用js多浏览器兼容纯DIV/CSS对联漂浮广告代码
- 兼容火狐、谷歌及IE的Javascript漂浮广告代码
- JavaScript自动设置IFrame高度(兼容各主流浏览器)
- javascript屏蔽Ctrl+s,F1,F3各浏览器兼容写法
- javascript 兼容多种浏览器
- Javascript之浏览器兼容EventUtil
- javascript在各个浏览器的兼容
- javascript 兼容所有浏览器的DOM扩展功能
- Javascript和CSS浏览器兼容总结
- Javascript和CSS浏览器兼容总结