电脑技术学习

网页浮动广告代码

dn001

本例主要是网页浮动广告代码,就是一个小框框在网页的右侧上下浮动。这个网页浮动广告代码的实现也很简单,在网页中通过javascript寻找id为divMenu的div,然后通过js代码来实现网页内的网页浮动广告。喜欢的就看演示吧,需要的就下载吧。代码最后分析。

请看html中的代码仔细研究下其实也不是很复杂,不想研究的就直接下载使用吧!
网页浮动广告代码的代码:

var bNetscape4plus = (navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) >= "4");
var bExplorer4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");
function CheckUIElements(){
; ;var yMenuFrom, yMenuTo, yButtonFrom, yButtonTo, yOffset, timeoutNextCheck;

; ;if ( bNetscape4plus ) {
; ;;;yMenuFrom; ;= document["divMenu"].top;
; ;;;yMenuTo; ;;;= top.pageYOffset + 295;
; ;}
; ;else if ( bExplorer4plus ) {
; ;;;yMenuFrom; ;= parseInt (divMenu.style.top, 10);
; ;;;yMenuTo; ;;;= document.body.scrollTop + 135; //距页面顶部的距离
; ;}

; ;timeoutNextCheck = 500;

; ;if ( Math.abs (yButtonFrom - (yMenuTo + 152)) < 6 && yButtonTo < yButtonFrom ) {
; ;;;setTimeout ("CheckUIElements()", timeoutNextCheck);
; ;;;return;
; ;}

; ;if ( yButtonFrom != yButtonTo ) {
; ;;;yOffset = Math.ceil( Math.abs( yButtonTo - yButtonFrom ) / 10 );
; ;;;if ( yButtonTo < yButtonFrom )
; ; yOffset = -yOffset;

; ;;;if ( bNetscape4plus )
; ; document["divLinkButton"].top += yOffset;
; ;;;else if ( bExplorer4plus )
; ; divLinkButton.style.top = parseInt (divLinkButton.style.top, 10) + yOffset;

; ;;;timeoutNextCheck = 10;
; ;}
; ;if ( yMenuFrom != yMenuTo ) {
; ;;;yOffset = Math.ceil( Math.abs( yMenuTo - yMenuFrom ) / 20 );
; ;;;if ( yMenuTo < yMenuFrom )
; ; yOffset = -yOffset;

; ;;;if ( bNetscape4plus )
; ; document["divMenu"].top += yOffset;
; ;;;else if ( bExplorer4plus )
; ; divMenu.style.top = parseInt (divMenu.style.top, 10) + yOffset;

; ;;;timeoutNextCheck = 10;
; ;}

; ;setTimeout ("CheckUIElements()", timeoutNextCheck);
}

function onl oad()
{
; ;var y;
; ;if ( top.frames.length )
; ;if ( bNetscape4plus ) {
; ;;;document["divMenu"].top = top.pageYOffset + 135;
; ;;;document["divMenu"].visibility = "visible";
; ;}
; ;else if ( bExplorer4plus ) {
; ;;;divMenu.style.top = document.body.scrollTop + 235;
; ;;;divMenu.style.visibility = "visible";
; ;}
; ;CheckUIElements();
; ;return true;
}
OnLoad();

标签: