//判断浏览器,如果是ie isIe=true;
var isIe=(document.all)?true:false;
/*
*设置名字为select的对象的所有样式是否可用
* state ---是否可以见
**/
function setSelectState(state) {
var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++) {
objl[i].style.visibility=state;
}
}
/*
*获取对象的坐标值
*
***/
function mousePosition(ev) {
if(ev.pageX || ev.pageY) {
return {
x:ev.pageX, y:ev.pageY
};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
/*
*弹出层的方法
* wTitle ---层的标题
* content ---层内的内容
* pos ---坐标对象
* wWidth ---层的宽度
*/
function showMessageBox(wTitle,content,pos,wWidth) {
closeWindow();
//获取游览器的可视区域宽与高
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);
//alert(bWidth+"___"+bHeight);
//设置可见度
if(isIe){
setSelectState('hidden');
}
//创建弹出层的背景div
var back=document.createElement("div");
//设置背景div的id
back.id="back";
//样式字符串
var styleStr="top:0px;left:0px;position:absolute;background:#003973;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
//给背景div设置样式
back.style.cssText=styleStr;
//将背景div加入到body中
document.body.appendChild(back);
//调用让背景渐渐变暗的方法
showBackground(back,50);
//创建消息层
var mesW=document.createElement("div");
mesW.id="mesWindow";
mesW.className="mesWindow";
mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'><img src='images/closeImg.gif' onClick='closeWindow();' alt='关闭'/></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
styleStr="left:"+(((pos.x-wWidth)>0)?(pos.x-wWidth):pos.x)+"px;top:"+(pos.y)+"px;position:absolute;width:"+wWidth+"px;";
mesW.style.cssText=styleStr;
//添加到body中
document.body.appendChild(mesW);
}
/*
*让背景渐渐变暗
* obj ---背景层对象
* endInt ---变暗效果的参数
**/
function showBackground(obj,endInt) {
if(isIe) {
obj.filters.alpha.opacity+=1;
if(obj.filters.alpha.opacity<endInt) {
setTimeout(function(){showBackground(obj,endInt)},5);
}
}else{
var al=parseFloat(obj.style.opacity);al+=0.01;
obj.style.opacity=al;
if(al<(endInt/100)) {
setTimeout(function(){showBackground(obj,endInt)},5);
}
}
}
//关闭窗口
function closeWindow() {
if(document.getElementById('back')!=null) {
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null){
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
if(isIe){
setSelectState('');
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页