我试图让 div“bio-button”类既打开隐藏文本的 div 又降低其自身的不透明度。然后当文本的 div 关闭时,它返回到之前的状态
如果你看this fiddle demo ,我想要的效果和你点击图片时的效果是一样的。
但我似乎遇到了调用太多函数的问题。我怎样才能更有效地实现这一目标?
j查询:
$('.bio-button').on('click', function () {
$(this).parent('img').css({opacity:1});
});
这是我的 html:
<div id="" class="team-member">
<div class="team-text">
<p>hello this is Billy's text</p>
<div class="close"></div>
</div><!-- .team-text -->
<div class="team-photo">
<img width="437" height="293" src="http://www.mgrear.com/clients/gls/wp-content/uploads/2013/02/billy.jpg" class="" alt="billy" />
<h2>Billy Senecal</h2>
<p>Producer / Director</p>
</div><!-- .team-photo -->
<div class="bio-button">BIO</div>
<div class="clear"></div>
</div><!-- #team-member -->
<div id="" class="team-member">
<div class="team-text">
<p>THis is Mark's text</p>
<div class="close"></div>
</div><!-- .team-text -->
<div class="team-photo">
<img width="439" height="293" src="http://www.mgrear.com/clients/gls/wp-content/uploads/2013/02/mark.jpg" class="" alt="mark" />
<h2>Mark Montalto</h2>
<p>Editor / Producer</p>
</div><!-- .team-photo -->
<div class="bio-button">BIO</div>
<div class="clear"></div>
最佳答案
试试这个:
$('.bio-button').on('click', function () {
$(this).prev('.team-photo').children('img').css({opacity:1});
});
分解:
当点击.bio-button
时,查看前面相邻的具有team-photo
类的兄弟,然后获取img
元素是 team-photo
元素的子元素,然后对 img
元素进行指定的 CSS 调整。
在上面的例子中,$(this)
指的是被点击的元素:$('.bio-button')
。
关于jQuery点击功能增加不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15394288/