現在很多網站廣告做的如火如荼現在我就來介紹一下常見的對聯浮動廣告效果的代碼使用方法本文介紹的這種效果在*分辨率下正常顯示在*的分辨率下可以自動隱藏以免遮住頁面影響訪問者浏覽內容而且與前面一個代碼不同的是當鼠標移動到廣告圖片上是可以感應顯示另外設置好的廣告大圖效果下面文本框中就是實現效果所需代碼
function bigshow(){
document
all
div_
style
visibility =
visible
;
document
all
div_
style
visibility =
hidden
;
}
function bighide(){
document
all
div_
style
visibility =
visible
;
document
all
div_
style
visibility =
hidden
;
}
var ad_
= new Array(
);
var ad_
= new Array(
);
ad_
[
]=
<a href= target=_blank><img src=/img
/js
_
gif border=
></a>
;
ad_
[
]=
<a href= target=_blank><img src=/img
/js
_
gif border=
></a>
;
var imgheight;
var fubioleft;
window
screen
width>
? fubioleft=
:fubioleft=
document
write(
<DIV id=floater_left >
);
ad_now = new Date();
ad_id= ad_now
getSeconds() %
var adhead
=
<div id=div_
style=
position:absolute; width:
px; height:
px; z
index:
onMouseOver=bigshow();>
;
var adhead
=
</div><div id=div_
style=
position:absolute; visibility: hidden; z
index:
;width:
; height:
onMouseOut=bighide();>
;
document
write(adhead
+ad_
[ad_id]+adhead
+ad_
[ad_id]+
</div>
);
document
write (
</div>
);
self
onError=null;
currentX = currentY =
;
whichIt = null;
lastScrollX =
; lastScrollY =
;
NS = (document
layers) ?
:
;
IE = (document
all) ?
:
;
function heartBeat() {
if(IE) {
diffY = document
body
scrollTop;
diffX = document
body
scrollLeft; }
if(NS) {
diffY = self
pageYOffset; diffX = self
pageXOffset; }
if(diffY != lastScrollY) {
percent =
* (diffY
lastScrollY);
if(percent >
) percent = Math
ceil(percent);
else percent = Math
floor(percent);
if(IE) document
all
floater_left
style
pixelTop += percent;
if(NS) document
floater_left
top += percent;
lastScrollY = lastScrollY + percent;
}
if(diffX != lastScrollX) {
percent =
* (diffX
lastScrollX);
if(percent >
) percent = Math
ceil(percent);
else percent = Math
floor(percent);
if(IE) document
all
floater_left
style
pixelLeft += percent;
if(NS) document
floater_left
left += percent;
lastScrollX = lastScrollX + percent;
}
}
if(NS || IE) action = window
setInterval(
heartBeat()
);var ad_
= new Array(
);
var ad_
= new Array(
);
ad_
[
]=
<a href= target=_blank><img src=/img
/js
_
gif border=
></a>
;
ad_
[
]=
<a href= target=_blank><img src=/img
/js
_
gif border=
></a>
;
var imgheight;
var fubioleft;
window
screen
width>
? fubioleft=
:fubioleft=
document
write(
<DIV id=floater_right >
);
ad_now = new Date();
ad_id= ad_now
getSeconds() %
function myload()
{
if (navigator
appName ==
Netscape
)
{
document
div_right_
pageX=+window
innerWidth
;
document
div_right_
pageX=+window
innerWidth
;
mymove();
}
else
{
div_right_
style
left=document
body
offsetWidth
;
div_right_
style
left=document
body
offsetWidth
;
mymove();
}
}
function mymove()
{
if(document
ns)
{
document
div_right_
left=pageXOffset+window
innerWidth
;
document
div_right_
left=pageXOffset+window
innerWidth
;
setTimeout(
mymove();
)
}
else
{
div_right_
style
left=document
body
scrollLeft+document
body
offsetWidth
;
div_right_
style
left=document
body
scrollLeft+document
body
offsetWidth
;
setTimeout(
mymove();
)
}
}
var adhead
=
<div id=div_right_
style=
position:absolute; width:
px; height:
px; z
index:
onMouseOver=bigshow_right();>
;
var adhead
=
</div><div id=div_right_
style=
position:absolute; visibility: hidden; z
index:
;width:
; height:
onMouseOut=bighide_right();><div align=right>
;
document
write(adhead
+ad_
[ad_id]+adhead
+ad_
[ad_id]+
</div></div>
);
myload()
document
write (
</div>
);
self
onError=null;
currentX_right = currentY_right =
;
whichIt_right = null;
lastScrollX_right =
; lastScrollY_right =
;
NS = (document
layers) ?
:
;
IE = (document
all) ?
:
;
function heartBeat_right() {
if(IE) {
diffY_right = document
body
scrollTop;
diffX_right = document
body
scrollLeft; }
if(NS) {
diffY_right = self
pageYOffset; diffX_right = self
pageXOffset; }
if(diffY_right != lastScrollY_right) {
percent_right =
* (diffY_right
lastScrollY_right);
if(percent_right >
) percent_right = Math
ceil(percent_right);
else percent_right = Math
floor(percent_right);
if(IE) document
all
floater_right
style
pixelTop += percent_right;
if(NS) document
floater_right
top += percent_right;
lastScrollY_right = lastScrollY_right + percent_right;
}
if(diffX_right != lastScrollX_right) {
percent_right =
* (diffX_right
lastScrollX_right);
if(percent_right >
) percent_right = Math
ceil(percent_right);
else percent_right = Math
floor(percent_right);
if(IE) document
all
floater_right
style
pixelLeft += percent_right;
if(NS) document
floater_right
left += percent_right;
lastScrollX_right = lastScrollX_right + percent_right;
}
}
if(NS || IE) action = window
setInterval(
heartBeat_right()
);
function bigshow_right(){
document
all
div_right_
style
visibility =
visible
;
document
all
div_right_
style
visibility =
hidden
;
}
function bighide_right(){
document
all
div_right_
style
visibility =
visible
;
document
all
div_right_
style
visibility =
hidden
;
}document
write(
);
document
write(
);
document
write(
);
把上面的代碼另存為一個JS文件然後在想實現此效果的頁面用<script type=text/javascript language=javascript src=*js></SCRIPT>調用即可*代表你另存的文件名!注意修改廣告圖片地址和連接地址!
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19165.html