代码
// JavaScript Document
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("lovexin12").style.top=parseInt(document.getElementById("lovexin12").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
//alert(lastScrollY);
}
suspendcode12="<DIV id=\"lovexin12\" style='right:10px;POSITION:absolute;TOP:30px;'><a href='http://www.rtbook.com/' target='_blank'><img border=0 src=http://www.ca800.com/book/img/readbuy.gif><br><a href=JavaScript:; onclick=\"lovexin12.style.display='none'\"><img border=0 src=http://www.ca800.com/book/images/close.gif></a></div>"
document.write(suspendcode12);
window.setInterval("heartBeat()",1);
//********************************************************
//另外一个
<div style=" height:100px; 118px; visibility: visible; position: absolute; left: 1024px; top: 420px; z-index: 10000; " id="floaterAd" >
<div id="closeDiv" style="cursor:move; text-align:right;" >关闭</div>
<!-- <div style="background-color:#316ac5 ;height:50px">this is atest </div> -->
<div >
<table width="89" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td><img width="89" height="114" border="0" usemap="#Map" src="http://www.ca800.com/subdir/paragon//images/qq.gif"/></td>
</tr></tbody>
</table>
<map name="Map" id="Map">
<area href="tencent://message/?uin=215653080&Site=215653080&Menu=yes" coords="6,83,85,105" shape="RECT"/>
</map>
</div>
</div>
<script>
self.onError = function() {
return ture;
};
function GetObj(id){return typeof(id)=="string"?document.getElementById(id):id }
var tq_fixJQueryMouseMoveEvent = null;
var Drag = {
obj: null,
init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
o.onmousedown = Drag.start;
o.hmode = bSwapHorzRef ? false: true;
o.vmode = bSwapVertRef ? false: true;
o.root = oRoot && oRoot != null ? oRoot: o;
if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
o.minX = typeof minX != 'undefined' ? minX: null;
o.minY = typeof minY != 'undefined' ? minY: null;
o.maxX = typeof maxX != 'undefined' ? maxX: null;
o.maxY = typeof maxY != 'undefined' ? maxY: null;
o.xMapper = fXMapper ? fXMapper: null;
o.yMapper = fYMapper ? fYMapper: null;
o.root.onDragStart = new Function();
o.root.onDragEnd = new Function();
o.root.onDrag = new Function()
},
start: function(e) {
var o = Drag.obj = this;
e = Drag.fixE(e);
var y = parseInt(o.vmode ? o.root.style.top: o.root.style.bottom);
var x = parseInt(o.hmode ? o.root.style.left: o.root.style.right);
o.root.onDragStart(x, y);
o.lastMouseX = e.clientX;
o.lastMouseY = e.clientY;
if (o.hmode) {
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX
} else {
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x
}
if (o.vmode) {
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY
} else {
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y
}
if (tq_fixJQueryMouseMoveEvent == null) tq_fixJQueryMouseMoveEvent = document.onmousemove;
document.onmousemove = Drag.drag;
document.onmouseup = Drag.end;
return false
},
drag: function(e) {
e = Drag.fixE(e);
var o = Drag.obj;
var ey = e.clientY;
var ex = e.clientX;
var y = parseInt(o.vmode ? o.root.style.top: o.root.style.bottom);
var x = parseInt(o.hmode ? o.root.style.left: o.root.style.right);
var nx,
ny;
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1: -1));
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1: -1));
if (o.xMapper) nx = o.xMapper(y);
else if (o.yMapper) ny = o.yMapper(x);
Drag.obj.root.style[o.hmode ? "left": "right"] = nx + "px";
Drag.obj.root.style[o.vmode ? "top": "bottom"] = ny + "px";
Drag.obj.lastMouseX = ex;
Drag.obj.lastMouseY = ey;
Drag.obj.root.onDrag(nx, ny);
return false
},
end: function() {
document.onmousemove = tq_fixJQueryMouseMoveEvent;
document.onmouseup = null;
Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left": "right"]), parseInt
(Drag.obj.root.style[Drag.obj.vmode ? "top": "bottom"]));
Drag.obj = null
},
fixE: function(e) {
if (typeof e == 'undefined') e = window.event;
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
return e
}
};
function resetPos() {
GetObj("floaterAd").style.left = (GetWinWidth() - parseInt(GetObj("floaterAd").style.width) - rightX) + "px";
}
var IE = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4));
var FF = (navigator.appName == "Netscape");
function GetWinWidth() {
if (IE) {
if (document.documentElement.clientHeight == 0) {
winH = document.body.clientHeight;
winW = document.body.clientWidth;
} else {
winH = document.documentElement.clientHeight - 2;
winW = document.documentElement.clientWidth - 2;
}
}
if (FF) {
winH = (document.documentElement.clientHeight);
winW = (document.documentElement.clientWidth);
}
return winW;
}
function getScrollTop() {
if (document.documentElement && document.documentElement.scrollTop) {
posY = document.documentElement.scrollTop
} else if (document.body) {
posY = document.body.scrollTop
} else if (window.innerHeight) {
posY = window.pageYOffset
}
if (posY == "undefined") posY = 0;
return posY
}
function getScrollLeft() {
if (document.documentElement && document.documentElement.scrollLeft) {
posX = document.documentElement.scrollLeft
} else if (document.body) {
posX = document.body.scrollLeft
} else if (window.innerWidth) {
posX = window.pageXOffset
}
if (posX == "undefined") posX = 0;
return posX
}
function getOffsetHeight() {
var HTMLtype = (document.documentElement.offsetHeight) ? "document.documentElement": "document.body";
var height = eval(HTMLtype).offsetHeight;
return height
}
function getOffsetWidth() {
var HTMLtype = (document.documentElement.offsetWidth) ? "document.documentElement": "document.body";
var width = eval(HTMLtype).offsetWidth;
return width
}
lastScrollX = 0;
lastScrollY = 0;
var IsFloatClose = false;
function setPosition() {
var diffY = getScrollTop();
var diffX = getScrollLeft();
if (diffY != lastScrollY) {
var percent = .1 * (diffY - lastScrollY);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
temptop = parseInt(GetObj("floaterAd").style.top);
GetObj("floaterAd").style.top = percent + temptop + "px";
lastScrollY = lastScrollY + percent;
}
if (diffX != lastScrollX) {
var percent = .1 * (diffX - lastScrollX);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
var templeft = parseInt(GetObj("floaterAd").style.left);
GetObj("floaterAd").style.left = percent + templeft + "px";
lastScrollX = lastScrollX + percent;
}
}
//***************************元素坐标尺寸 bbs.51js.com/thread-67628-1-1.html
function getLTWH(o)
{
function getCurrentStyle(style)
{
var number=parseInt(o.currentStyle[style]);
return isNaN(number)?0:number;
}
function getComputedStyle(style)
{
return parseInt(document.defaultView.getComputedStyle(o,null).getPropertyValue(style));
}
var IE = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4));
var FF = (navigator.appName == "Netscape");
//alert(FF);
var oLTWH=
{
"left":o.offsetLeft,
"top":o.offsetTop,
"width":o.offsetWidth,
"height":o.offsetHeight
};
while(true)
{
o=o.offsetParent;
if(o==(document.body&&null))break;
oLTWH.left+=o.offsetLeft;
oLTWH.top+=o.offsetTop;
if(IE)
{
oLTWH.left+=getCurrentStyle("borderLeftWidth");
oLTWH.top+=getCurrentStyle("borderTopWidth");
}
if(FF)
{
oLTWH.left+=getComputedStyle("border-left-width");
oLTWH.top+=getComputedStyle("border-top-width");
}
}
return oLTWH;
}
//********************
var rightX = 0;
if (parseInt(GetObj("floaterAd").style.left) < 0) {
rightX = -parseInt(GetObj("floaterAd").style.left);
resetPos();
}
window.onresize = function() {
resetPos()
};
window.setInterval("setPosition()", 20);
//nowPosX=GetObj("floaterAd").offsetLeft;
nowPosX= getLTWH(GetObj("floaterAd")).left;
Drag.init(GetObj("closeDiv"),GetObj("floaterAd"),nowPosX,nowPosX);
</script>
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("lovexin12").style.top=parseInt(document.getElementById("lovexin12").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
//alert(lastScrollY);
}
suspendcode12="<DIV id=\"lovexin12\" style='right:10px;POSITION:absolute;TOP:30px;'><a href='http://www.rtbook.com/' target='_blank'><img border=0 src=http://www.ca800.com/book/img/readbuy.gif><br><a href=JavaScript:; onclick=\"lovexin12.style.display='none'\"><img border=0 src=http://www.ca800.com/book/images/close.gif></a></div>"
document.write(suspendcode12);
window.setInterval("heartBeat()",1);
//********************************************************
//另外一个
<div style=" height:100px; 118px; visibility: visible; position: absolute; left: 1024px; top: 420px; z-index: 10000; " id="floaterAd" >
<div id="closeDiv" style="cursor:move; text-align:right;" >关闭</div>
<!-- <div style="background-color:#316ac5 ;height:50px">this is atest </div> -->
<div >
<table width="89" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td><img width="89" height="114" border="0" usemap="#Map" src="http://www.ca800.com/subdir/paragon//images/qq.gif"/></td>
</tr></tbody>
</table>
<map name="Map" id="Map">
<area href="tencent://message/?uin=215653080&Site=215653080&Menu=yes" coords="6,83,85,105" shape="RECT"/>
</map>
</div>
</div>
<script>
self.onError = function() {
return ture;
};
function GetObj(id){return typeof(id)=="string"?document.getElementById(id):id }
var tq_fixJQueryMouseMoveEvent = null;
var Drag = {
obj: null,
init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
o.onmousedown = Drag.start;
o.hmode = bSwapHorzRef ? false: true;
o.vmode = bSwapVertRef ? false: true;
o.root = oRoot && oRoot != null ? oRoot: o;
if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
o.minX = typeof minX != 'undefined' ? minX: null;
o.minY = typeof minY != 'undefined' ? minY: null;
o.maxX = typeof maxX != 'undefined' ? maxX: null;
o.maxY = typeof maxY != 'undefined' ? maxY: null;
o.xMapper = fXMapper ? fXMapper: null;
o.yMapper = fYMapper ? fYMapper: null;
o.root.onDragStart = new Function();
o.root.onDragEnd = new Function();
o.root.onDrag = new Function()
},
start: function(e) {
var o = Drag.obj = this;
e = Drag.fixE(e);
var y = parseInt(o.vmode ? o.root.style.top: o.root.style.bottom);
var x = parseInt(o.hmode ? o.root.style.left: o.root.style.right);
o.root.onDragStart(x, y);
o.lastMouseX = e.clientX;
o.lastMouseY = e.clientY;
if (o.hmode) {
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX
} else {
if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x
}
if (o.vmode) {
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY
} else {
if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y
}
if (tq_fixJQueryMouseMoveEvent == null) tq_fixJQueryMouseMoveEvent = document.onmousemove;
document.onmousemove = Drag.drag;
document.onmouseup = Drag.end;
return false
},
drag: function(e) {
e = Drag.fixE(e);
var o = Drag.obj;
var ey = e.clientY;
var ex = e.clientX;
var y = parseInt(o.vmode ? o.root.style.top: o.root.style.bottom);
var x = parseInt(o.hmode ? o.root.style.left: o.root.style.right);
var nx,
ny;
if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1: -1));
ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1: -1));
if (o.xMapper) nx = o.xMapper(y);
else if (o.yMapper) ny = o.yMapper(x);
Drag.obj.root.style[o.hmode ? "left": "right"] = nx + "px";
Drag.obj.root.style[o.vmode ? "top": "bottom"] = ny + "px";
Drag.obj.lastMouseX = ex;
Drag.obj.lastMouseY = ey;
Drag.obj.root.onDrag(nx, ny);
return false
},
end: function() {
document.onmousemove = tq_fixJQueryMouseMoveEvent;
document.onmouseup = null;
Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left": "right"]), parseInt
(Drag.obj.root.style[Drag.obj.vmode ? "top": "bottom"]));
Drag.obj = null
},
fixE: function(e) {
if (typeof e == 'undefined') e = window.event;
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
return e
}
};
function resetPos() {
GetObj("floaterAd").style.left = (GetWinWidth() - parseInt(GetObj("floaterAd").style.width) - rightX) + "px";
}
var IE = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4));
var FF = (navigator.appName == "Netscape");
function GetWinWidth() {
if (IE) {
if (document.documentElement.clientHeight == 0) {
winH = document.body.clientHeight;
winW = document.body.clientWidth;
} else {
winH = document.documentElement.clientHeight - 2;
winW = document.documentElement.clientWidth - 2;
}
}
if (FF) {
winH = (document.documentElement.clientHeight);
winW = (document.documentElement.clientWidth);
}
return winW;
}
function getScrollTop() {
if (document.documentElement && document.documentElement.scrollTop) {
posY = document.documentElement.scrollTop
} else if (document.body) {
posY = document.body.scrollTop
} else if (window.innerHeight) {
posY = window.pageYOffset
}
if (posY == "undefined") posY = 0;
return posY
}
function getScrollLeft() {
if (document.documentElement && document.documentElement.scrollLeft) {
posX = document.documentElement.scrollLeft
} else if (document.body) {
posX = document.body.scrollLeft
} else if (window.innerWidth) {
posX = window.pageXOffset
}
if (posX == "undefined") posX = 0;
return posX
}
function getOffsetHeight() {
var HTMLtype = (document.documentElement.offsetHeight) ? "document.documentElement": "document.body";
var height = eval(HTMLtype).offsetHeight;
return height
}
function getOffsetWidth() {
var HTMLtype = (document.documentElement.offsetWidth) ? "document.documentElement": "document.body";
var width = eval(HTMLtype).offsetWidth;
return width
}
lastScrollX = 0;
lastScrollY = 0;
var IsFloatClose = false;
function setPosition() {
var diffY = getScrollTop();
var diffX = getScrollLeft();
if (diffY != lastScrollY) {
var percent = .1 * (diffY - lastScrollY);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
temptop = parseInt(GetObj("floaterAd").style.top);
GetObj("floaterAd").style.top = percent + temptop + "px";
lastScrollY = lastScrollY + percent;
}
if (diffX != lastScrollX) {
var percent = .1 * (diffX - lastScrollX);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
var templeft = parseInt(GetObj("floaterAd").style.left);
GetObj("floaterAd").style.left = percent + templeft + "px";
lastScrollX = lastScrollX + percent;
}
}
//***************************元素坐标尺寸 bbs.51js.com/thread-67628-1-1.html
function getLTWH(o)
{
function getCurrentStyle(style)
{
var number=parseInt(o.currentStyle[style]);
return isNaN(number)?0:number;
}
function getComputedStyle(style)
{
return parseInt(document.defaultView.getComputedStyle(o,null).getPropertyValue(style));
}
var IE = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4));
var FF = (navigator.appName == "Netscape");
//alert(FF);
var oLTWH=
{
"left":o.offsetLeft,
"top":o.offsetTop,
"width":o.offsetWidth,
"height":o.offsetHeight
};
while(true)
{
o=o.offsetParent;
if(o==(document.body&&null))break;
oLTWH.left+=o.offsetLeft;
oLTWH.top+=o.offsetTop;
if(IE)
{
oLTWH.left+=getCurrentStyle("borderLeftWidth");
oLTWH.top+=getCurrentStyle("borderTopWidth");
}
if(FF)
{
oLTWH.left+=getComputedStyle("border-left-width");
oLTWH.top+=getComputedStyle("border-top-width");
}
}
return oLTWH;
}
//********************
var rightX = 0;
if (parseInt(GetObj("floaterAd").style.left) < 0) {
rightX = -parseInt(GetObj("floaterAd").style.left);
resetPos();
}
window.onresize = function() {
resetPos()
};
window.setInterval("setPosition()", 20);
//nowPosX=GetObj("floaterAd").offsetLeft;
nowPosX= getLTWH(GetObj("floaterAd")).left;
Drag.init(GetObj("closeDiv"),GetObj("floaterAd"),nowPosX,nowPosX);
</script>