当前位置: 首页 > news >正文

点击图片1.全屏阅览2.下载3.关闭 纯纯html css js

要实现图片点击全屏预览的功能,可以使用JavaScript和CSS来实现。以下是一个简单的示例代码:

html

<!DOCTYPE html>
<html>
<head><meta charsett="UTF-8"><title>图片点击全屏预览</title><style>/* 全屏预览样式 */.fullscreen {position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.8);display: flex;justify-content: center;align-items: center;z-index: 9999;}.fullscreen img {max-width: 90%;max-height: 90%;}.fullscreen img:hover {cursor: pointer;}/* 关闭按钮样式 */.close-btn {position: absolute;top: 10px;right: 10px;color: #fff;font-size: 24px;cursor: pointer;}/* 下载按钮样式 */.download-btn {position: absolute;bottom: 10px;right: 10px;color: #fff;font-size: 24px;cursor: pointer;}</style>
</head>
<body><img src="image.jpg" alt="图片" onclick="openFullscreen(this)"><script>function openFullscreen(img) {// 创建全屏预览容器var fullscreenDiv = document.createElement("div");fullscreenDiv.classList.add("fullscreen");// 创建关闭按钮var closeBtn = document.createElement("span");closeBtn.classList.add("close-btn");closeBtn.innerHTML = "&times;";closeBtn.onclick = function() {closeFullscreen();};fullscreenDiv.appendChild(closeBtn);// 创建下载按钮var downloadBtn = document.createElement("span");downloadBtn.classList.add("download-btn");downloadBtn.innerHTML = "&#x2193;";downloadBtn.onclick = function() {downloadImage(img.src);};fullscreenDiv.appendChild(downloadBtn);// 创建图片元素var fullscreenImg = document.createElement("img");fullscreenImg.src = img.src;fullscreenDiv.appendChild(fullscreenImg);// 添加全屏预览容器到页面document.body.appendChild(fullscreenDiv);// 禁用滚动document.body.style.overflow = "hidden";}function closeFullscreen() {// 移除全屏预览容器var fullscreenDiv = document.querySelector(".fullscreen");fullscreenDiv.parentNode.removeChild(fullscreenDiv);// 启用滚动document.body.style.overflow = "auto";}function downloadImage(src) {// 创建一个隐藏的链接并设置下载属性var link = document.createElement("a");link.href = src;link.download = "image.jpg";link.style.display = "none";// 将链接添加到页面并模拟点击document.body.appendChild(link);link.click();document.body.removeChild(link);}</script>
</body>
</html>

在上面的代码中,我们首先定义了一个全屏预览的样式,并在点击图片时调用openFullscreen函数。该函数会创建一个全屏预览容器,并在容器中显示图片。同时,我们还创建了关闭按钮和下载按钮,分别用于关闭全屏预览和下载图片。

点击关闭按钮时,调用closeFullscreen函数,移除全屏预览容器,并启用滚动。

点击下载按钮时,调用downloadImage函数,创建一个隐藏的链接,并设置链接的下载属性,然后模拟点击链接实现图片下载。

请注意,这只是一个简单的示例,实际的图片全屏预览功能可能需要更多的优化和处理,例如支持多张图片预览、滑动切换等。根据具体需求,您可以根据上述示例进行扩展和修改。

http://www.lryc.cn/news/100733.html

相关文章:

  • 科技项目验收测试:验证软件产品功能与性能的有效手段
  • Spring MVC学习笔记,包含mvc架构使用,过滤器、拦截器、执行流程等等
  • 【LeetCode 算法】Linked List Cycle 环形链表
  • RedHat7.9安装mysql8.0.32 ↝ 二进制方式
  • 数据库面试题题
  • 瑞吉外卖项目 基于spring Boot+mybatis-plus开发 超详细笔记,有源码链接
  • Redis Cluster 在Spring中遇到的问题
  • linux远程桌面管理工具 xrdp
  • 硬件-8-操作系统的历史
  • self.register_buffer()中的值发生变化
  • [Tools: Pycharm] Bug合集
  • 【JAVASE】循环结构
  • NoSQL之Redis配置使用
  • Ansible最佳实践之Playbook使用过滤器处理网络地址
  • 测试常见前端bug
  • 【Python数据分析】Python常用内置函数(一)
  • OpenCV图像处理-图像分割-MeanShift
  • 【Rust 基础篇】Rust Trait 实现:灵活的接口抽象
  • 【嵌入式Linux项目】基于Linux的全志H616开发板智能家居项目(语音控制、人脸识别、安卓APP和PC端QT客户端远程操控)有视频功能展示
  • ElasticSearch基础篇-条件查询与映射
  • 大模型部署框架 FastLLM 实现细节解析
  • Flutter ios真机调试连接断开后应用闪退
  • 序列化,反序列化之实例
  • 2022年全国职业院校技能大赛(高职组)“软件测试”赛项竞赛任务书
  • 第18节:R语言分析:临床安全性数据的数据分析
  • 36.悬浮板
  • BLE基础理论/Android BLE开发示例
  • rocketmq 5.13任意时间延迟消息
  • 小程序picker 在苹果手机不兼容 bug,按month时在iPhone 显示不正确及自动定位时间问题
  • 区块链服务网络的顶层设计与应用实践