如何使用 esc 键关闭灯箱页面叠加
我对灯箱有疑问,请参阅我的 jsFiddle。 单击其中一张图像将打开该画作的更大版本作为页面叠加层。
如何使用ESC键关闭此页面覆盖?
以及如何使用方向键移动到下一张图像?
我需要什么样的 jQuery 插件/javascript 才能实现这一点?
<ul class="lb-album">
<li>
<a href="#Fly-My-Pretties-Walled-Garden">
<img src="http://sandipa.com.au/images/works-for-sale/thumbs/Fly-my-Pretties-Walled-Garden-sm.jpg" alt="Fly My Pretties: Walled Garden">
<span>Fly My Pretties</span> </a>
<div class="lb-overlay" id="Fly-My-Pretties-Walled-Garden">
<a href="#page" class="lb-close">x Close</a>
<img src="http://sandipa.com.au/images/2010-2011/1000px-wide/Fly-my-Pretties-Walled-Garden.jpg" alt="Fly My Pretties: Walled Garden">
<div>
<h3>Fly My Pretties: Walled Garden<span>mixed media on canvas</span></h3>
<p>72 x 137 cm</p>
<a href="#Light-that-Shapes-the-Shadows" class="lb-prev">Prev</a>
<a href="#Central-Highlands-Circle-of-Gold" class="lb-next">Next</a>
</div>
</div>
</li>
<li>
<a href="#Central-Highlands-Circle-of-Gold">
<img src="http://sandipa.com.au/images/works-for-sale/thumbs/Central-Highlands-Circle-of-Gold-sm.jpg" alt="Central Highlands: Circle of Gold">
<span>Circle of Gold</span> </a>
<div class="lb-overlay" id="Central-Highlands-Circle-of-Gold">
<a href="#page" class="lb-close">x Close</a>
<img src="http://sandipa.com.au/images/works-for-sale/Central-Highlands-Circle-of-Gold.jpg" alt="Central Highlands: Circle of Gold">
<div>
<h3>Central Highlands: Circle of Gold<span>mixed media on canvas</span></h3>
<p>51 x 108 cm</p>
<a href="#Fly-My-Pretties-Walled-Garden" class="lb-prev">Prev</a>
<a href="#Guardian-of-the-Night" class="lb-next">Next</a>
</div>
</div>
</li>
</ul>
I have a question about a lightbox see my jsFiddle.
Clicking on one of the images opens a bigger version of the painting as a page overlay.
How to use the ESC key to close this page overlay?
And how to use the arrow keys to move to the next image?
What kind of jQuery plugin / javascript would I need to make this happen?
<ul class="lb-album">
<li>
<a href="#Fly-My-Pretties-Walled-Garden">
<img src="http://sandipa.com.au/images/works-for-sale/thumbs/Fly-my-Pretties-Walled-Garden-sm.jpg" alt="Fly My Pretties: Walled Garden">
<span>Fly My Pretties</span> </a>
<div class="lb-overlay" id="Fly-My-Pretties-Walled-Garden">
<a href="#page" class="lb-close">x Close</a>
<img src="http://sandipa.com.au/images/2010-2011/1000px-wide/Fly-my-Pretties-Walled-Garden.jpg" alt="Fly My Pretties: Walled Garden">
<div>
<h3>Fly My Pretties: Walled Garden<span>mixed media on canvas</span></h3>
<p>72 x 137 cm</p>
<a href="#Light-that-Shapes-the-Shadows" class="lb-prev">Prev</a>
<a href="#Central-Highlands-Circle-of-Gold" class="lb-next">Next</a>
</div>
</div>
</li>
<li>
<a href="#Central-Highlands-Circle-of-Gold">
<img src="http://sandipa.com.au/images/works-for-sale/thumbs/Central-Highlands-Circle-of-Gold-sm.jpg" alt="Central Highlands: Circle of Gold">
<span>Circle of Gold</span> </a>
<div class="lb-overlay" id="Central-Highlands-Circle-of-Gold">
<a href="#page" class="lb-close">x Close</a>
<img src="http://sandipa.com.au/images/works-for-sale/Central-Highlands-Circle-of-Gold.jpg" alt="Central Highlands: Circle of Gold">
<div>
<h3>Central Highlands: Circle of Gold<span>mixed media on canvas</span></h3>
<p>51 x 108 cm</p>
<a href="#Fly-My-Pretties-Walled-Garden" class="lb-prev">Prev</a>
<a href="#Guardian-of-the-Night" class="lb-next">Next</a>
</div>
</div>
</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
纯 Javascript Lightbox 或 Image Popup Modal 的完整实现可以在我的答案中找到,网址为 https://stackoverflow.com/a/67169851/ 8210884。
上面链接中提到的这个答案允许处理使用ESC键隐藏灯箱的问题以及使用左和右浏览灯箱中的图像的问题> 箭头键。
以下是该答案中的代码片段,它将帮助我们解决这两个问题。
使用ESC键隐藏灯箱:
使用左右箭头键浏览灯箱中网页上的所有图像:
这些与按键事件相关的条件情况< /strong> 在
document.onkeydown = function(event)
中处理。下面的这段代码对于禁用 IMG 标签上按键事件的默认行为以及在数组中堆叠网页上的所有图像以允许使用向左和向右箭头键在 Lightbox 中导航。
A full implementation of Pure Javascript Lightbox or Image Popup Modal is available in one my Answers at https://stackoverflow.com/a/67169851/8210884.
This Answer mentioned in the link above allows handling both the issues of Hiding Lightbox with ESC key as well as navigating through images in Lightbox using Left and Right arrow key.
Here are the Pieces of code from that Answer which will help us achieve these Two issues.
Hiding the Lightbox with ESC key :
Navigating through all the images on a Webpage in Lightbox with Left and Right Arrow key :
These conditional cases related to Key Pressing events are tackled in
document.onkeydown = function(event)
.This piece of code below is very important for disabling the default behaviours of Key pressing events on IMG tags as well as stacking up all the images on a webpage in an Array to allow Navigation in Lightbox with Left and Right arrow key.