【发布时间】:2011-07-30 22:00:38
【问题描述】:
我在一个页面上有三张图片,我想淡出未点击的元素。该脚本在第一个实例中有效,因此如果您单击一张图片,其他两张会消失。如果您认为单击已褪色的图片,所发生的只是最后一张未褪色的图片也会褪色,而不是 100% 不透明度和其他两个褪色。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<style>
.opac {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
border:thick;
}
</style>
<script>
$(document).ready(function(){
$('a.images').click(function()
{
$(this).siblings().stop().animate({opacity: 0.4}, 300);
$('a.images').click(function()
{
$not('this').stop().animate({opacity: 1.0}, 300);
});
});
});
</script>
</head>
html
<body>
<div id="images">
<a class="images" href="#"><img class="click" src="../appalachia.jpg" height="133" /><br/><br/></a>
<a class="images" href="#"><img class="click" src="../appalachia.jpg" height="133" /><br/><br/></a>
<a class="images" href="#"><img class="click" src="../appalachia.jpg" height="133" /><br/><br/></a>
</div>
</body>
</html>
【问题讨论】:
-
您不再需要
-khtml-*规则,它们已经过时了。另外别忘了在IE zoom: 1触发hasLayout,否则filter将不会被应用。 -
@Marcel:你需要
-webkit-*规则吗? -
@Rocket:根据MDC,普通的
opacity被当前所有基于WebKit 的浏览器支持,所以:不,你也不需要那些。顺便说一句,-moz-opacity也是如此。
标签: javascript jquery css opacity