简体   繁体   English

当我单击其他div时使div出现

[英]Make div appear when i click in other div

I have five different div's with class 'avatar' and when I click on one of them, I want the respective section with 'iframe' class to appear. 我有五个不同的div,其类别为“ avatar”,当我单击其中的一个时,我希望相应的带有“ iframe”类别的部分出现。 So far I've only been able to create a function in which when I click on the div with class 'avatar', the .open class is added causing the section of classse .iframe to appear. 到目前为止,我只能创建一个函数,当我单击带有“ avatar”类的div时,将添加.open类,从而导致出现类.iframe的部分。 But it's always the same section that pops up. 但是总是弹出相同的部分。

HTML 的HTML

<div class="avatar" id="mauricioAvatar">
    <img src="img/mauricio.jpg" alt="">
    <span class="avatar-info"><p><strong>Maurício Munhoz</strong><br/>
    Diretor/Consultor Técnico</p>
    </span>
</div>
<div class="avatar" id="alexandreAvatar">
   <img src="img/alexandre.jpeg" alt="">
    <span class="avatar-info"><p><strong>Alexandre Lúcio da Silva</strong><br/>
    Consultor Lean Manufacturing</p>
    </span>
</div>
<div class="avatar" id="pauloAvatar">
    <img src="img/paulo.jpg" alt="">
    <span class="avatar-info"><p><strong>Paulo Fernandes da Costa</strong><br/>
    Consultor Técnico</p>
    </span>
</div>
<div class="avatar" id="amauriAvatar">
    <img src="img/amauri.png" alt="">
    <span class="avatar-info"><p><strong>Amauri Chillemi</strong><br/>
    Consultor Técnico</p>
    </span>
</div>
<div class="avatar" id="julianoAvatar">
    <img src="img/juliano.jpg" alt="">
    <span class="avatar-info"><p><strong>Juliano Eibel</strong><br/>
    Desenvolvedor Front-End</p>
    </span>
</div>

section's that should appear 应显示的部分

<section class="iframe">
    <div class="iframe_avatar">
        <img src="img/mauricio.jpg" alt="">
    </div>
    <div class="iframe_info">
       <span class="iframe_close">&times;</span>
        <p><strong>Maurício Munhoz</strong><br/>
                Diretor/Consultor Técnico</p>
        <p>Formado em Engenharia Industrial pela Universidade Braz Cubas de Moji das Cruzes - SP. Antes de fundar a Munhoz Consultoria, Maurício atuou como Engenheiro e Supervisor da Qualidade na Valeo Sistemas Automotivos Ltda, com a coordenação de equipes de técnicos e engenheiros, planejamento de atividades, tratamento de não conformidades, planejamento e gerenciamento de custos e investimentos da área da qualidade, negociação em compras e aprovação de projetos. </p>
    </div>
</section>
<section class="iframe">
    <div class="iframe_avatar">
        <img src="img/alexandre.jpeg" alt="">
    </div>
    <div class="iframe_info">
       <span class="iframe_close">&times;</span>
        <p><strong>Alexandre Lúcio da Silva</strong><br/>
                Diretor/Consultor Técnico</p>
        <p>Formado em Engenharia Industrial pela Universidade Braz Cubas de Moji das Cruzes - SP. Antes de fundar a Munhoz Consultoria, Maurício atuou como Engenheiro e Supervisor da Qualidade na Valeo Sistemas Automotivos Ltda, com a coordenação de equipes de técnicos e engenheiros, planejamento de atividades, tratamento de não conformidades, planejamento e gerenciamento de custos e investimentos da área da qualidade, negociação em compras e aprovação de projetos. </p>
    </div>
</section>

JS JS

$(".avatar").click(function() {
   $('.iframe').addClass('open');
});

As you want to open corresponding iframe class section then use .index() along with .eq() 当您要打开相应的iframe类部分时,请同时使用.index().eq()

$(".avatar").click(function() { // index
   $('.iframe').eq($(this).index()).addClass('open'); // matched index
});

Using the index of the div class to open would help. 使用div类的索引打开将有所帮助。 https://api.jquery.com/index/ https://api.jquery.com/index/

ex - get the index of the iframe/class using ".index()" then compare if the index matches then add the class open. ex-使用“ .index()”获取iframe /类的索引,然后比较索引是否匹配,然后添加打开的类。 Please see the jquery index documentation. 请参阅jquery索引文档。

html html

<section id="iframe_0" class="iframe"></section>
<section id="iframe_1" class="iframe hidden"></section>
<section id="iframe_2" class="iframe hidden"></section>

css 的CSS

.hidden {
    display: none;
}

js js

$(".avatar").on('click', function() {
    var i = 2;

    $('.iframe').addClass("hidden");
    $('#iframe_' + i).removeClass("hidden");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM