Home > Web Front-end > JS Tutorial > It can run under the w3c declaration and has good compatibility. js couplet advertising collection_javascript skills

It can run under the w3c declaration and has good compatibility. js couplet advertising collection_javascript skills

WBOY
Release: 2016-05-16 18:04:53
Original
1156 people have browsed it

最后我们给出合适的代码:
核心代码:

复制代码 代码如下:

lastScrollY=0;
function heartBeat(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}

//alert(diffY);
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("leftDIV").style.top=parseInt(document.getElementById("leftDIV").style.top) percent "px";
document.getElementById("rightDIV").style.top=parseInt(document.getElementById("leftDIV").style.top) percent "px";

lastScrollY=lastScrollY percent;
//alert(lastScrollY);
}

sidebar1= "
"
sidebar2= "
"

document.write(sidebar1);
document.write(sidebar2);

//下面这段删除后,对联将不跟随屏幕而移动。
window.setInterval("heartBeat()",1);
//-->

function closeAD()
{
document.getElementById("leftDIV").style.display='none';
document.getElementById("rightDIV").style.display='none';
}

为了防止冲突,我们修改后的代码:
因为客户只需要右侧的代码,左侧的我们留空。
复制代码 代码如下:

lastScrollY=0;
function heartBeat2(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}

//alert(diffY);
percent=.1*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("leftDIV2").style.top=parseInt(document.getElementById("leftDIV2").style.top) percent "px";
document.getElementById("rightDIV2").style.top=parseInt(document.getElementById("leftDIV2").style.top) percent "px";

lastScrollY=lastScrollY percent;
//alert(lastScrollY);
}

sidebar1= "
"
sidebar2= "
"

document.write(sidebar1);
document.write(sidebar2);

//下面这段删除后,对联将不跟随屏幕而移动。
window.setInterval("heartBeat2()",1);
//-->
function closeAD()
{
document.getElementById("leftDIV2").style.display='none';
document.getElementById("rightDIV2").style.display='none';
}

后来经过网上查找,又发现了一个不错的代码

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

Js对联广告代码
经典的对联广告代码,JS代码实现,很简洁,也是通用的代码,随着滚动条的滚动自动适应,对联大小由CSS控制,这使得代码修改起来更加方便快捷,不懂JS也没有关系。不过本代码有一处遗憾就是没有关闭功能,真想用的可以自己加一个。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template