在我下面的代码中不透明 [英] not working opacity in my below code..
本文介绍了在我下面的代码中不透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
<script type="text/javascript">
window.size = function()
{
var w = 0;
var h = 0;
//IE
if(!window.innerWidth)
{
//strict mode
if(!(document.documentElement.clientWidth == 0))
{
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
}
//quirks mode
else
{
w = document.body.clientWidth;
h = document.body.clientHeight;
}
}
//w3c
else
{
w = window.innerWidth;
h = window.innerHeight;
}
return {width:w,height:h};
}
window.size = function()
{
var w = 0;
var h = 0;
//IE
if(!window.innerWidth)
{
//strict mode
if(!(document.documentElement.clientWidth == 0))
{
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
}
//quirks mode
else
{
w = document.body.clientWidth;
h = document.body.clientHeight;
}
}
//w3c
else
{
w = window.innerWidth;
h = window.innerHeight;
}
return {width:w,height:h};
}
window.center = function()
{
var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
var _x = 0;
var _y = 0;
var offsetX = 0;
var offsetY = 0;
//IE
if(!window.pageYOffset)
{
//strict mode
if(!(document.documentElement.scrollTop == 0))
{
offsetY = document.documentElement.scrollTop;
offsetX = document.documentElement.scrollLeft;
}
//quirks mode
else
{
offsetY = document.body.scrollTop;
offsetX = document.body.scrollLeft;
}
}
//w3c
else
{
offsetX = window.pageXOffset;
offsetY = window.pageYOffset;
}
_x = ((this.size().width-hWnd.width)/2)+offsetX;
_y = ((this.size().height-hWnd.height)/2)+offsetY;
return{x:_x,y:_y};
}
var bgObj=document.createElement("ss");
function showCenter(point)
{
debugger;
var msgw,msgh,bordercolor;
msgw=400;//Width
msgh=238;//Height
titleheight=25; //title Height
bordercolor="#336699";//boder color
titlecolor="#99CCFF";//title color
var sWidth,sHeight;
sWidth=document.body.offsetWidth;
sHeight=screen.height;
// var bgObj=document.createElement("ss");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="fixed";
bgObj.style.top="0";
bgObj.style.background="#777";
bgObj.style.filter="alpha(opacity=50);zoom:1;"
bgObj.style.opacity="0.5";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
var msgObj=document.createElement("light");
// msgObj.setAttribute("id","msgDiv");
//document.getElementById('light').style.display='block';
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
// msgObj.style.top = point.y + "px";
// msgObj.style.left = point.x + "px";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.filter = "alpha(opacity=0.5)";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
// document.body.removeChild(msgObj);
document.body.appendChild(bgObj);
document.body.appendChild(msgObj);
}
</script>
</head>
<body>
<div runat="server">
<a href = "javascript:void(0)" class="sublink" onclick ="showCenter()">sss</a>
</div>
</body>
</html>
推荐答案
尝试一下
bgObj.style.opacity=0.5;
(不带引号)
正如Shameel所建议的那样,它可以工作,但是(愚蠢的)IE无法识别CSS的不透明度标准.对浏览器进行检查,对于IE使用以下方法:
As Shameel suggested, it would work but (stupid) IE does not recognise the CSS standards for opacity. Do a check for the browser, and for IE use this:
bgObj.style.filter = ''alpha(opacity='' + ''60'' + '')'';
这篇关于在我下面的代码中不透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文