87,910
社区成员
发帖
与我相关
我的任务
分享
var oElementNeedSet = null;
function SetPosition(sBrowser)
{//alert(oElementNeedSet.style.width);
var addLeft = document.documentElement.scrollLeft;
var addTop = document.documentElement.scrollTop;
var eleLeft = document.documentElement.clientWidth - oElementNeedSet.width + addLeft;
var eleTop = document.documentElement.clientHeight - oElementNeedSet.height + addTop;
if (sBrowser == "safari")
//{alert('document.documentElement.clientWidth: ' + document.documentElement.clientWidth + '\r'
// + 'document.documentElement.clientHeight: ' + document.documentElement.clientHeight);
addLeft = document.body.scrollLeft;
addTop = document.body.scrollTop;
var eleLeft = document.documentElement.clientWidth - oElementNeedSet.width + addLeft;
var eleTop = document.documentElement.clientHeight - oElementNeedSet.height + addTop;
}
oElementNeedSet.style.left = eleLeft + "px";
oElementNeedSet.style.top = eleTop + "px";
}
function InitLoad(sElementID)
{
if (oElementNeedSet == null)
{
oElementNeedSet = document.getElementById(sElementID);
}
var sBrowser = getBrowser();
if (sBrowser == "IE6")
{
SetPosition(sBrowser);
oElementNeedSet.style.position = "absolute";
window.onscroll = function()
{
SetPosition(sBrowser);
}
}
else
{
SetPosition(sBrowser);
oElementNeedSet.style.position = "fixed";
}
}
function getBrowser()
{
var sResult = "other";
var s = navigator.userAgent.toLowerCase();//alert(s);
var a = new Array("msie", "firefox", "safari", "opera", "netscape");
for(var i = 0; i < a.length; i ++)
{
if(s.indexOf(a[i]) != -1)
{
sResult = a[i];
}
}
if (sResult == "msie")
{
sResult = "IE6";
if (window.XMLHttpRequest)
{
sResult = "IE7";
}
}
return sResult;
}