是否可以从另一个元素触发 data-featherlight-gallery?
Is it possible to trigger a data-featherlight-gallery from another element?
我正在尝试从另一个元素触发隐藏的 "lightbox" 图库。
在这种情况下,有一个 触发器 和一个 data-featherlight-gallery。
触发器应该弹出灯箱,就像您单击 data-featherlight-gallery.
中的链接一样
HTML
// when you click on this div
<div class="trigger">
<a href="#"></a><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
</div>
<hr>
// you should be able to trigger the behaviour of this featherlight gallery
<div class="toggle">
<h3>Gallery</h3>
<div data-featherlight-gallery data-featherlight-filter="a">
<a href="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_b.jpg"><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
<a href="http://farm5.staticflickr.com/4005/4400559493_3403152632_o.jpg"><img src="http://farm5.staticflickr.com/4005/4400559493_f652202d1b_q.jpg" /></a>
<a href="http://farm1.staticflickr.com/174/396673914_be9d1312b1_o.jpg"><img src="http://farm1.staticflickr.com/174/396673914_be9d1312b1_q.jpg" /></a>
</div>
</div>
我做了一个 JSfiddle:http://jsfiddle.net/joaoalvesmarrucho/JNsu6/595/
非常感谢任何帮助。
我对 data-feather 库不是很熟悉,但您似乎只想显示图库中的第一张图片。如果是这样的话,我们可以用一些小的 CSS 来做到这一点,比如:
#gallery>a ~ a {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/noelboss/featherlight/master/src/featherlight.js"></script>
<script src="https://rawgit.com/noelboss/featherlight/master/src/featherlight.gallery.js"></script>
<link href="https://rawgit.com/noelboss/featherlight/master/src/featherlight.css" rel="stylesheet"/>
<link href="https://rawgit.com/noelboss/featherlight/master/src/featherlight.gallery.css" rel="stylesheet"/>
<div>
<h3>Gallery</h3>
<div id="gallery" data-featherlight-gallery data-featherlight-filter="a">
<a href="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_b.jpg"><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
<a href="http://farm5.staticflickr.com/4005/4400559493_3403152632_o.jpg"><img src="http://farm5.staticflickr.com/4005/4400559493_f652202d1b_q.jpg" /></a>
<a href="http://farm1.staticflickr.com/174/396673914_be9d1312b1_o.jpg"><img src="http://farm1.staticflickr.com/174/396673914_be9d1312b1_q.jpg" /></a>
</div>
</div>
请注意在数据羽化 div 中添加了一个 gallery
id,并且 css 样式隐藏了除第一个之外的所有 a
子元素。
我正在尝试从另一个元素触发隐藏的 "lightbox" 图库。 在这种情况下,有一个 触发器 和一个 data-featherlight-gallery。 触发器应该弹出灯箱,就像您单击 data-featherlight-gallery.
中的链接一样HTML
// when you click on this div
<div class="trigger">
<a href="#"></a><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
</div>
<hr>
// you should be able to trigger the behaviour of this featherlight gallery
<div class="toggle">
<h3>Gallery</h3>
<div data-featherlight-gallery data-featherlight-filter="a">
<a href="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_b.jpg"><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
<a href="http://farm5.staticflickr.com/4005/4400559493_3403152632_o.jpg"><img src="http://farm5.staticflickr.com/4005/4400559493_f652202d1b_q.jpg" /></a>
<a href="http://farm1.staticflickr.com/174/396673914_be9d1312b1_o.jpg"><img src="http://farm1.staticflickr.com/174/396673914_be9d1312b1_q.jpg" /></a>
</div>
</div>
我做了一个 JSfiddle:http://jsfiddle.net/joaoalvesmarrucho/JNsu6/595/
非常感谢任何帮助。
我对 data-feather 库不是很熟悉,但您似乎只想显示图库中的第一张图片。如果是这样的话,我们可以用一些小的 CSS 来做到这一点,比如:
#gallery>a ~ a {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/noelboss/featherlight/master/src/featherlight.js"></script>
<script src="https://rawgit.com/noelboss/featherlight/master/src/featherlight.gallery.js"></script>
<link href="https://rawgit.com/noelboss/featherlight/master/src/featherlight.css" rel="stylesheet"/>
<link href="https://rawgit.com/noelboss/featherlight/master/src/featherlight.gallery.css" rel="stylesheet"/>
<div>
<h3>Gallery</h3>
<div id="gallery" data-featherlight-gallery data-featherlight-filter="a">
<a href="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_b.jpg"><img src="http://farm8.staticflickr.com/7070/6874560581_dc2b407cc0_q.jpg" /></a>
<a href="http://farm5.staticflickr.com/4005/4400559493_3403152632_o.jpg"><img src="http://farm5.staticflickr.com/4005/4400559493_f652202d1b_q.jpg" /></a>
<a href="http://farm1.staticflickr.com/174/396673914_be9d1312b1_o.jpg"><img src="http://farm1.staticflickr.com/174/396673914_be9d1312b1_q.jpg" /></a>
</div>
</div>
请注意在数据羽化 div 中添加了一个 gallery
id,并且 css 样式隐藏了除第一个之外的所有 a
子元素。