Discuz! 兼容的对联广告代码
<script type="text/javascript">
<!--
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);
}
//下面这段删除后,对联将不跟随屏幕而移动。
window.setInterval("heartBeat()",1);
//-->
</script>
<style type="text/css">
<!--
/* 这里定义滴是页面高度,用来测试对联跟随效果滴,跟广告无关 */
html,body{height:1000px;}
#mm{height:1000px;}
/* 这里是设置对联样式滴 */
#leftDiv,#rightDiv{
width:88px; /* 宽度 */
height:448px; /* 高度 */
background-color:#e5e5e5; /* 背景颜色 */
border:1px solid #ddd; /* 边框样式 */
position:absolute; /* 绝对定位激活 */
}
-->
</style>
<div id="leftDiv" style="top:120px; /* 距离顶部120px */ left:2px; /* 距离左侧2px */ "><img src="/images/mbsp.gif" alt="说明"></div>
<div id="rightDiv" style="top:120px; /* 距离顶部120px */ right:2px; /* 距离右侧2px */ "><img src="/images/mbsp.gif" alt="说明"></div>
代码二
<script type="text/javascript">
var isIE = /msie/i.test(navigator.userAgent);
function gID(id){return document.getElementById(id);}
function ScrollDiv(id,pScrollY){
var ScrollY = document.documentElement.scrollTop || document.body.scrollTop;
if (pScrollY ==null) { pScrollY=0; }
var moveTop = .1 * (ScrollY - pScrollY);
moveTop = (moveTop > 0) ? Math.ceil(moveTop) : Math.floor(moveTop);
gID(id).style.top = parseInt(gID(id).style.top) + moveTop + "px";
pScrollY = pScrollY + moveTop;
setTimeout("ScrollDiv('"+id+"',"+pScrollY+");",50);
}
function addObjEvent(obj,eventName,eventFunc){
if (obj.attachEvent){
obj.attachEvent(eventName,eventFunc);
}else if (obj.addEventListener){ //FF Gecko / W3C
var eventName2 = eventName.toString().replace(/on(.*)/i,'$1');
obj.addEventListener(eventName2,eventFunc, false);
}else{
obj = eventFunc;
}
}
function delObjEvent(obj,eventName,eventFunc){
if (obj.detachEvent) {
obj.detachEvent(eventName,eventFunc);
}else if (obj.removeEventListener){ //FF Gecko / W3C
var eventName2 = eventName.toString().replace(/on(.*)/i,'$1');
obj.removeEventListener(eventName2,eventFunc, false);
}else{
obj = null;
}
}
function MoveDiv(obj,e){
e = e||window.event;
var ie6=isIE;
if (/msie 9/i.test(navigator.userAgent)) {ie6=false;}
if (ie6 && e.button == 1 || !ie6 && e.button == 0) {}else{return false;}
obj.style.position='absolute';
obj.ondragstart =function(){return false;}
var x = e.screenX - obj.offsetLeft;
var y = e.screenY - obj.offsetTop;
addObjEvent(document,'onmousemove',moving);
addObjEvent(document,'onmouseup',endMov);
e.cancelBubble = true;
if (isIE) {
obj.setCapture();
} else {
window.captureEvents(Event.mousemove);
}
if (e.preventDefault) {
e.preventDefault();
e.stopPropagation();
}
e.returnValue = false;
return false;
function moving(e){
obj.style.left = (e.screenX - x) + 'px';
obj.style.top = (e.screenY - y) + 'px';
return false;
}
function endMov(e){
delObjEvent(document,'onmousemove',moving);
delObjEvent(document,'onmouseup',arguments.callee);
if (isIE) {
obj.releaseCapture();
} else {
window.releaseEvents(Event.mousemove);
}
}
}
</script>
<style>
.KeFuDiv{
position: absolute;
height:160px;
width:118px;
z-index:9999;
}
</style>
<div id="KeFuDiv" class="KeFuDiv"><a href="https://www.xmspace.net" target="_blank"><img src="/app.png" alt="说明"></a></div>
<script>
gID("KeFuDiv").style.top = (document.documentElement.clientHeight - gID("KeFuDiv").offsetHeight)/4 +"px";
gID("KeFuDiv").style.right = document.documentElement.clientWidth - gID("KeFuDiv").offsetWidth - "10px" +"px";
ScrollDiv('KeFuDiv');
</script>
页:
[1]