gpt4 book ai didi

javascript - 对除一张图像以外的所有 body 应用不透明度

转载 作者:行者123 更新时间:2023-11-27 23:59:44 25 4
gpt4 key购买 nike

我有一个包含 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 中的所有 child 。而不是选择 div 中的所有 child ,而不是点击使用的 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);
});
});

DEMO

关于javascript - 对除一张图像以外的所有 body 应用不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21955594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com