TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How do you implement modal images?

1 点作者 Sujeto大约 2 年前
How do you build the modals to show expanded versions of images when you click them?<p>I&#x27;ve become opinionated on this. My guidelines are:<p>1) Use most of the screen available, something like 90% width&#x2F;height.<p>2) Close the image when clicking ANYWHERE on the modal. This includes the image itself.<p>3) No need for a close button.<p>This allows more viewing area and easy closing method if you know that you just have to click anywhere to go back to what you were doing.<p>Sites like Discord make it tough on me because they restrict the viewing area too much, they don&#x27;t expand much. And this is because they expect you to click on the surrounding area to close it. If clicking the image closed it they could expand more.<p>4) Have a button to expand images vertically.<p>This is for very long images.<p>I show first a normal version of the image where it is completely visible, but maybe hard to read. If the user chooses so they click a button which expands the image vertically and allows the user to scroll to read the image.<p>I experimented with expanding vertically automatically but I found this to be not very natural, as I expected to see the &quot;whole picture&quot; first.

1 comment

Sujeto大约 2 年前
A modal image on my site looks like this:<p><a href="https:&#x2F;&#x2F;i.imgur.com&#x2F;l2XCa2y.jpg" rel="nofollow">https:&#x2F;&#x2F;i.imgur.com&#x2F;l2XCa2y.jpg</a>