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

标签 javascript jquery html

我有一个包含 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);
    });
});

DEMO

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

相关文章:

javascript - 使用 AJAX 更新从数据库(mysql)检索的数据

javascript - 创建一个获取每个数组项并整理它的 JavaScript 对象

javascript - 如何在动态创建的函数调用中传递对象

html - 如何在 Angular 2 中轻轻更改 img src

javascript - 有什么方法可以使用点语法按名称调用方法吗?

javascript - hapi.js 与 auth 相关

jquery - Bootstrap Accordion 嵌套网格

jQuery ~ 如何检查输入值中的文本

php - 没有错误,但是我的记录没有被添加到我的数据库中

html - 响应式选择菜单布局