如何在纯 HTML 页面上创建悬停显示的缩略图?
我有一些大的 .png (.jpg, ...) 文件,几乎需要全屏才能查看。如何在标准 HTML 页面上创建缩略图?标签中是否有某种我错过的尺寸缩放控制?
当鼠标悬停在这样的缩略图上时可以显示大图像吗? (JavaScript 和 CSS 对于任一答案都可以)。
编辑:由于目标浏览器可能以不同的尺寸分辨率显示,因此如何使缩略图按比例缩放到网页/文本的显示尺寸?
I have some large .png (.jpg, ...) files that require pretty much a full screen to see. How do I create thumbnails on a standard HTML page? Is there some kind of size scaling control in the tag that I've somehow missed?
Can I get the large image to display when the mouse hovers over such a thumbnail?
(JavaScript and CSS are OK for either answer).
EDIT: Since target browsers may be showing at different size resolutions, how do I keep the thumbnail proportionally scaled to the displayed size of the web page/text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这项技术实际上无异于烟雾和镜子,因为这两个图像都是直接编码在页面上的。然而,较大的图像通过 CSS 变得不可见,只有当访问者将鼠标悬停在链接上时才可见。单击该链接将在新页面中打开全尺寸图像。上图的编码为:
分区内链接的图像通过 CSS 自动隐藏:
由于所有图像都会自动隐藏,因此需要将缩略图显示为实际链接之外的背景图像。为了使链接在图像上工作并在图像下方(而不是图像上方)显示文本,有必要包含以下代码:
当光标悬停在链接上方时,较大的图像将显示在链接上方:
The technique really amounts to smoke and mirrors, since both images are directly coded on the page. However, the larger image is made invisible through CSS and only becomes visible when the visitor hovers over the link. Clicking the link opens the full-size image in the new page. The image above is coded as:
Images that are linked within the division are automatically hidden through CSS:
Since all images are automatically hidden, it is necessary to display the thumbnail as a background image outside of the actual link. In order for the link to work over the image and display the text below the image (instead of over it), it is necessary to include this code:
The larger image is revealed above the link when the cursor is hovered over it: