将插件应用于多个DIV

问题描述 投票:0回答:1

我有以下内容:

<div class="gallery">
  <a href="http://via.placeholder.com/200x100?text=A1">
    <img src="http://via.placeholder.com/200x100?text=A1"/>
  </a>
  <a href="http://via.placeholder.com/200x100?text=A2">
    <img src="http://via.placeholder.com/200x100?text=A2"/>
  </a>
</div>

<div class="gallery">
  <a href="http://via.placeholder.com/200x100?text=B1">
    <img src="http://via.placeholder.com/200x100?text=B1"/>
  </a>
  <a href="http://via.placeholder.com/200x100?text=B2">
    <img src="http://via.placeholder.com/200x100?text=B2"/>
  </a>
</div>

然后使用http://dbrekalo.github.io/simpleLightbox我有:

$('.gallery a').simpleLightbox();

但这使得画廊“看到”页面中的所有图像都是同一个画廊。

我怎么称呼simpleLightbox所以每个Gallery Div都被视为画廊?

请注意,我在页面中有两个以上的画廊。

jquery
1个回答
2
投票

你可以在.each上使用.gallery并启动个人a.gallery插件

$('.gallery').each(function(){
   $(this).find("a").simpleLightbox();
})
© www.soinside.com 2019 - 2024. All rights reserved.