//先设置div position:absolute;
function fixDiv(divId){
var div=document.getElementById(divId);
var divSize=function(){return {'x': div.offsetWidth, 'y': div.offsetHeight}}();
div.style.cssText='top:'+window.clientHeight-divSize.y+';left:'+window.clientWidth-divSize.x;
return div;
}
function fixDiv(divId){
var div=document.getElementById(divId);
var divSize=function(){return {'x': div.offsetWidth, 'y': div.offsetHeight}}();
div.style.cssText='top:'+window.clientHeight-divSize.y+';left:'+window.clientWidth-divSize.x;
return div;
}
主要是使用body()那个函数获得正确的坐标值WebIMPopup.prototype.body=function()
{
var bodyST, bodyCH;
if(window.pageYOffset)
{bodyST=window.pageYOffset;}
else if(document.documentElement&&document.documentElement.scrollTop)
{bodyST=document.documentElement.scrollTop;}
else if(document.body)
{bodyST=document.body.scrollTop;}
if(window.innerHeight)
{bodyCH=window.innerHeight;}
else if(document.documentElement&&document.documentElement.clientHeight)
{bodyCH=document.documentElement.clientHeight;}
else if(document.body)
{bodyCH=document.body.clientHeight;}
var W, SL;
var w=window, d=document, dd=d.documentElement;
if(dd&&dd.clientWidth) W=dd.clientWidth;
else if(w.innerWidth) W=w.innerWidth;
else if(d.body) W=d.body.clientWidth;
if(w.pageXOffset) SL=w.pageXOffset;
else if(dd&&dd.scrollLeft) SL=dd.scrollLeft;
else if(d.body) SL=d.body.scrollLeft;
return {"scrollTop":bodyST,"scrollLeft":SL,"clientWidth":W,"clientHeight":bodyCH};
}WebIMPopup.prototype.setToRightCorner=function(divId)
{
var s=new WebIMPopup();
var ele=document.getElementById(divId);
if(s&&ele)
{
var body=s.body();
ele.style.top=(body.scrollTop+body.clientHeight-ele.offsetHeight-1)+"px";
ele.style.left=(body.scrollLeft+body.clientWidth-ele.offsetWidth-1)+"px";
}
}
然后每次window.scroll 和window.resize的时候都调用一下