返回到:Prototype – 元素对象
此方法设置元素的视觉不透明度,同时解决各种浏览器中的不一致问题。
opacity 参数应该是一个浮点数,其中 0 表示完全透明,1 表示完全不透明。
Element.setStyle方法在内部使用setOpacity来设置不透明度。
语法
element.setOpacity(opacity);
返回值
返回一个 HTML 元素。
例子
HTML
x
19
19
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function reduceOpacity() {
8
$('test').setOpacity( 0.5 );
9
// This is equivalent to
10
// Element.setStyle({ opacity: 0.5 });
11
}
12
</script>
13
</head>
14
15
<body">
16
<p id = "test">Click the button to see the result.</p>
17
<input type = "button" value = "Click" onclick = "reduceOpacity();"/>
18
</body>
19
</html>
返回到:Prototype – 元素对象
阅读剩余 73%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9008.html