zoukankan
html css js c++ java
JavaScript 对联广告、漂浮广告封装类(IE,FF,Opera,Safari,Chrome)
<
script type
=
"
text/javascript
"
>
function
$(element)
{
if
(arguments.length
>
1
)
{
for
(
var
i
=
0
,elements
=
[],length
=
arguments.length;i
<
length;i
++
)
elements.push($(arguments[i]));
return
elements;
}
if
(
typeof
element
==
"
string
"
)
return
document.getElementById(element);
else
return
element;
}
Function.prototype.bind
=
function
(object)
{
var
method
=
this
;
return
function
()
{
method.apply(object,arguments);
}
}
var
Class
=
{
create:
function
()
{
return
function
()
{
this
.initialize.apply(
this
,arguments);
}
}
}
Object.extend
=
function
(destination,resource)
{
for
(
var
property
in
resource)
{
destination[property]
=
resource[property];
}
return
destination;
}
//
对联广告类
var
float_ad
=
Class.create();
float_ad.prototype
=
{
initialize:
function
(id,content,top,left,width)
{
document.write(
'
<div id=
'
+
id
+
'
style="position:absolute;">
'
+
content
+
'
</div>
'
);
this
.id
=
$(id);
this
.top
=
top;
if
(
!!
left)
{
this
.id.style.left
=
"
8px
"
;
}
else
{
this
.id.style.left
=
(document.documentElement.clientWidth
-
width
-
8
)
+
"
px
"
;
window.onresize
=
function
()
{
this
.id.style.left
=
(document.documentElement.clientWidth
-
width
-
8
)
+
"
px
"
;
}
.bind(
this
);
}
this
.id.style.top
=
top
+
"
px
"
;
this
.interId
=
setInterval(
this
.scroll.bind(
this
),
20
);
}
,
scroll:
function
()
{
this
.stmnStartPoint
=
parseInt(
this
.id.style.top,
10
);
this
.stmnEndPoint
=
document.documentElement.scrollTop
+
this
.top;
if
(navigator.userAgent.indexOf(
"
Chrome
"
)
>
0
)
{
this
.stmnEndPoint
=
document.body.scrollTop
+
this
.top;
}
if
(
this
.stmnStartPoint
!=
this
.stmnEndPoint )
{
this
.stmnScrollAmount
=
Math.ceil( Math.abs(
this
.stmnEndPoint
-
this
.stmnStartPoint )
/
15
);
this
.id.style.top
=
parseInt(
this
.id.style.top,
10
)
+
( (
this
.stmnEndPoint
<
this
.stmnStartPoint )
?
-
this
.stmnScrollAmount :
this
.stmnScrollAmount )
+
"
px
"
;
}
}
}
/**/
/*
//漂浮广告类
var move_ad=Class.create();
move_ad.prototype={
initialize:function(imgOption,initPosition,delay){
this.imgOptions=Object.extend({url:"",link:"",alt:"",120,height:120},imgOption||{});
this.adPosition=Object.extend({left:40,top:120},initPosition||{});
this.delay =delay;
this.step = 1;
this.herizonFlag=true;
this.verticleFlag=true;
this.id="ad_move_sg";
var vHtmlString="<div id='"+this.id+"' style='position:absolute; left:"+this.adPosition.left+"px; top:"+this.adPosition.top+"px; "+this.imgOptions.width+"px;";
vHtmlString+=" height:"+this.imgOptions.height+"px; z-index:10;'><a href='"+this.imgOptions.link+"' target='_blank' title='"+this.imgOptions.alt+"'><img src='"+this.imgOptions.url+"' width='"+this.imgOptions.width+"' height='"+this.imgOptions.height+"' style='border:none;' alt='"+this.imgOptions.alt+"' /></a></div>";
document.write(vHtmlString);
this.id=$(this.id);
this.intervalId=setInterval(this.scroll.bind(this),this.delay);
this.id.onmouseover=this.stop.bind(this);
this.id.onmouseout=this.start.bind(this);
},
scroll:function(){
var L=T=0;
var B=document.documentElement.clientHeight-this.id.offsetHeight;
var R=document.documentElement.clientWidth-this.id.offsetWidth;
this.id.style.left=this.adPosition.left+document.documentElement.scrollLeft+"px";
this.id.style.top=this.adPosition.top+document.documentElement.scrollTop+"px";
this.adPosition.left =this.adPosition.left + this.step*(this.herizonFlag?1:-1);
if (this.adPosition.left < L) { this.herizonFlag = true; this.adPosition.left = L;}
if (this.adPosition.left > R){ this.herizonFlag = false; this.adPosition.left = R;}
this.adPosition.top =this.adPosition.top + this.step*(this.verticleFlag?1:-1);
if(this.adPosition.top <= T){ this.verticleFlag=true; this.adPosition.top=T;}
if(this.adPosition.top >= B){ this.verticleFlag=false; this.adPosition.top=B; }
},
stop:function(){
clearInterval(this.intervalId);
},
start:function(){
this.intervalId=setInterval(this.scroll.bind(this),this.delay);
}
}
*/
/**/
/*
对联广告调用
第一个参数为ID,第二个参数图片,第三个参数广告距离顶部的距离,
第四个参数表示左右(true代表左,false代表右),第五个参数对联广告的宽度
*/
new
float_ad(
"
ad_QQ
"
,
"
<a href=\
"
http:
//
liuju150.cnblogs.com\"><img src='http://qun.qq.com/cgi/svr/face/getface?type=1&uin=995506774' border=\"0\" /></a>",500,true,64);
//
new float_ad("ad_QQ","<img src='http://jzyouth.org.cn/images/float/2009Cherry.gif' />",50,false,64);
/**/
/*
漂浮广告调用
第一个参数中的url代表漂浮广告的图片URL地址(必选项),link链接到页面网址,alt图片提示文字,width图片的宽度(可选项,默认120),heihgt图片的高度(可选项,默认120)
第二个参数中的代表漂浮广告的初始位置,由参数left和top指定
第三个参数代表浮动速度,0为静止,越小浮动速度越快
*/
/**/
/*
new move_ad({url:"http://qun.qq.com/cgi/svr/face/getface?type=1&uin=995506774",link:"http://liuju150.cnblogs.com",alt:"刘巨(艾梦尔的博客)",200,height:200},{left:40,top:160},20);
*/
<
/
script>
都看完了,你确定不点个赞再走?
查看全文
相关阅读:
EELS
企业管理软件随想透视>包容,无形思想>有形方便
定风波
企业管理软件随想也谈企业框架软件需求
Delphi数据库开发-前言
游戏引发的……
js 当前时间
代码片段
阶段总结
Web界面设计
原文地址:https://www.cnblogs.com/liuju150/p/1563326.html
最新文章
Lesson_7 作业_2 NetUser
Lesson_9 作业_1 21点
Lesson_9 作业_2 工厂
Lesson_8 上课笔记 继承
Caterl java 寒假基础练习题(二) 判断闰年和简单递归
Lesson_8 作业_1 car和truck
在控制用' * '台画一个圆形图案
Lesson_7 作业_3 无名的粉
Lesson_8 课堂练习 继承.通讯工具
将外部图块插入当前图形(c#代码)
热门文章
无法将顶级控件添加到控件
c#枚举的用法及遍历方法
Sql2005导出SQL2000格式的脚本
使用Microsoft Visual Studio2005开发ObjectARX设置
Delphi quotedstr
一句话
自定义创建Visual Studio 2005代码段
测试下word
企业管理软件随想人格化
960 Grid System CSS Framework的原理和使用方法
Copyright © 2011-2022 走看看