使用JavaScript生成可编辑能够插入图片改变图片大小点击图片能够放大的网页表格

时间: 2024-03-24 21:41:48 浏览: 18
以下是使用JavaScript生成可编辑能够插入、改变大小、点击放大的网页表格的示例代码: ```html <!DOCTYPE html> <html> <head> <title>Editable Table with Resizable and Zoomable Images</title> <style> table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid black; padding: 5px; text-align: center; } th { background-color: #f2f2f2; } td { position: relative; } .resizable { border: 2px dotted black; position: absolute; right: 0; bottom: 0; width: 20px; height: 20px; cursor: nwse-resize; } .zoomable { cursor: zoom-in; max-width: 100%; max-height: 100%; } .overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: none; justify-content: center; align-items: center; } .overlay img { max-width: 90%; max-height: 90%; } </style> </head> <body> <h1>Editable Table with Resizable and Zoomable Images</h1> <table id="editable-table"> <thead> <tr> <th>Name</th> <th>Image</th> </tr> </thead> <tbody> <tr> <td contenteditable="true">Product 1</td> <td> <div class="image-container"> <img class="zoomable" src="" alt="No Image"> <div class="resizable"></div> </div> </td> </tr> <tr> <td contenteditable="true">Product 2</td> <td> <div class="image-container"> <img class="zoomable" src="" alt="No Image"> <div class="resizable"></div> </div> </td> </tr> </tbody> </table> <div class="overlay"> <img src="" alt=""> </div> <script> const resizable = document.querySelectorAll('.resizable'); const zoomable = document.querySelectorAll('.zoomable'); const overlay = document.querySelector('.overlay'); const overlayImage = document.querySelector('.overlay img'); // Make images resizable resizable.forEach(handle => { const container = handle.parentElement; const image = container.querySelector('.zoomable'); let startX, startY, startWidth, startHeight; const handleResize = event => { const newWidth = startWidth + (event.clientX - startX); const newHeight = startHeight + (event.clientY - startY); container.style.width = `${newWidth}px`; container.style.height = `${newHeight}px`; image.style.width = `${newWidth}px`; image.style.height = `${newHeight}px`; }; handle.addEventListener('mousedown', event => { event.preventDefault(); event.stopPropagation(); startX = event.clientX; startY = event.clientY; startWidth = parseInt(document.defaultView.getComputedStyle(container).width, 10); startHeight = parseInt(document.defaultView.getComputedStyle(container).height, 10); document.addEventListener('mousemove', handleResize); document.addEventListener('mouseup', () => { document.removeEventListener('mousemove', handleResize); }); }); }); // Make images zoomable zoomable.forEach(image => { image.addEventListener('click', () => { overlayImage.src = image.src; overlay.style.display = 'flex'; }); }); // Close overlay on click overlay.addEventListener('click', () => { overlay.style.display = 'none'; }); </script> </body> </html> ``` 该代码会生成一个带有两行可编辑的表格,每行包含一个可编辑的文本单元格和一个包含可调整大小和可放大的图像的单元格。当用户选择图像并上传时,JavaScript代码会在单元格中显示图像,并允许用户拖动边缘来调整大小,以及单击图像以放大它。单击放大的图像会使其在另一个覆盖层中显示。您可以根据需要添加更多行或自定义样式。

相关推荐

最新推荐

recommend-type

用javascript实现点击链接弹出图片另存为而不是直接打开

&lt;iframe height=”0″ width=”0″ src=”/images/logo.gif” name=”saveImage” id=”saveImage”&gt;&lt;/iframe&gt; &lt;a&gt;Click Me&lt;/a&gt;
recommend-type

javascript实现图片左右滚动效果【可自动滚动,有左右按钮】

本文实例讲述了javascript实现图片左右滚动效果。分享给大家供大家参考,具体如下: html代码: &lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8" /&gt; &lt;meta ...
recommend-type

JS实现将链接生成二维码并转为图片的方法

主要介绍了JS实现将链接生成二维码并转为图片的方法,涉及qrcodejs插件及js图片生成相关操作技巧,需要的朋友可以参考下
recommend-type

Python3实现抓取javascript动态生成的html网页功能示例

主要介绍了Python3实现抓取javascript动态生成的html网页功能,结合实例形式分析了Python3使用selenium库针对javascript动态生成的HTML网页元素进行抓取的相关操作技巧,需要的朋友可以参考下
recommend-type

javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法

主要介绍了javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法,涉及javascript鼠标事件及页面元素样式操作的相关技巧,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。