我有一个包含 3 个图像的 html 代码
<html>
<head>
<title>Tias</title>
<link rel="stylesheet" type="text/css" href="../css/estilo.css">
<script src="../js/jquery.js"></script>
<script src="../js/animate.js"></script>
</head>
<body>
<div class="cuerpo">
<h1>Tias famosas</h1>
<img src="has.jpg" class="tias-imagen">
<img src="dew.jpg" class="tias-imagen">
<img src="hola.jpg" class="tias-imagen">
</div>
</body>
然后我有一个js文件
$(document).ready(function(){
$(".tias-imagen").on('click', function() {
$(this).animate({
width: "70%",
height: "800px",
marginLeft: "0.6in",
fontSize: "3em",
borderWidth: "10px"
}, 1500 );
$(".cuerpo").not(this).animate({
opacity: "0.4"
}, 1500);
});
});
因此,当我单击图像时,我希望不透明度背景的不透明度为 0,4。
但我不希望不透明度应用于图像。
但是在 js 代码中,它确实为所有元素设置了不透明度。
最佳答案
您正在使用 .cuerpo
类对 div 应用不透明度。所以它会影响 div 中的所有子项。相反,选择 div
中没有单击的 image
的所有子项:
$(document).ready(function(){
$(".tias-imagen").on('click', function() {
$(this).animate({
width: "70%",
height: "800px",
marginLeft: "0.6in",
fontSize: "3em",
borderWidth: "10px"
}, 1500 );
$(".cuerpo").find("*").not(this).animate({
opacity: "0.4"
}, 1500);
});
});
关于javascript - 对除一张图像之外的所有 body 应用不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21955594/