插件基于jquery,所以必须引入jquery包.
先看预览图:
1 引入js和css
servlet后台需要的包:
2 html中放置按钮 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DiskFileItemFactory factory= new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> list = null ; try { list = upload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } String id = request.getParameter("id"); TGreens t = null; try { t = service.getTGreens(id); } catch (SQLException e) { e.printStackTrace(); } for(int i=0;i<list.size();i++){ FileItem item =list.get(i); if(item.isFormField()){ }else{ InputStream is = item.getInputStream(); String path = getServletContext().getRealPath("/upload"); //保存到tomcat安装目录 String fileName = item.getName(); //文件名 System.out.println("======================="+fileName); String hz = fileName.substring(fileName.lastIndexOf("."));//取后缀 String uuid = UUID.randomUUID().toString(); OutputStream os = new FileOutputStream(path+"//"+uuid+""+hz); int len =0; byte[] b = new byte[1024]; while((len=is.read(b))>-1){ os.write(b, 0, len); } os.close(); t.setGimg("upload/"+uuid+""+hz); try { service.update(t); //插入数据库 } catch (SQLException e) { e.printStackTrace(); } PrintWriter out = response.getWriter(); out.print(path+"/"+uuid+hz); out.close(); } } } |
资源下载和demo演示地址:http://demo.sucaihuo.com/1085/程序员都懂的,右键查看源代码即可下载css和js了 |
本文中,我们将了解HTML拖放,并借助示例了解其实现.
拖放是一个非常交互式和用户友好的概念,它可以通过抓住对象更轻松地将对象移动到其他位置。这允许用户在元素上单击并按住鼠标按钮,将其拖动到其他位置,然后释放鼠标按钮以将元素放到该位置。在HTML 5中,拖放更容易编码,其中的任何元素都是可拖动的。
拖放事件:有各种拖放事件,其中一些在下面列出:
拖放 Drag and Drop实现步骤:
例1:
<!DOCTYPE HTML>
<html>
<head>
<style>
#getData {
width: 250px;
height: 200px;
padding: 10px;
border: 1px solid #4f4d4d;
}
</style>
<script>
function allowDrop(even) {
even.preventDefault();
}
function drag(even) {
even.dataTransfer.setData("text", even.target.id);
}
function drop(even) {
even.preventDefault();
var fetchData = even.dataTransfer.getData("text");
even.target.appendChild(document.getElementById(fetchData));
}
</script>
</head>
<body>
<h3>Drag the GeekforGeeks image into the rectangle:</h3>
<div id="getData"
ondrop="drop(event)"
ondragover="allowDrop(event)">
</div>
<br>
<img id="dragData"
src="gfg.png"
draggable="true"
ondragstart="drag(event)"
width="250"
height="200">
</body>
</html>
Output:
Dragging the image into the box
拖放过程的数据传递: 当拖放的整个过程发生时,将使用数据传输属性。它用于保存从源拖放到所需位置的数据。这些是与之关联的属性:
例2:
<!DOCTYPE HTML>
<html>
<head>
<title>Drag and Drop box</title>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function dragStart(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function dragDrop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
<style>
#box {
margin: auto;
width: 50%;
height: 200px;
border: 3px solid green;
padding: 10px;
}
#box1,
#box2,
#box3 {
float: left;
margin: 5px;
padding: 10px;
}
#box1 {
width: 50px;
height: 50px;
background-color: #F5B5C5;
}
#box2 {
width: 100px;
height: 100px;
background-color: #B5D5F5;
}
#box3 {
width: 150px;
height: 150px;
background-color: #BEA7CC;
}
p {
font-size: 20px;
font-weight: bold;
text-align: center;
}
.gfg {
font-size: 40px;
color: #009900;
font-weight: bold;
text-align: center;
}
</style>
</head>
<body>
<div class="gfg">GeeksforGeeks</div>
<p>Drag and drop of boxes</p>
<div id="box">
<div id="box1" draggable="true"
ondragstart="dragStart(event)">
</div>
<div id="box2" draggable="true"
ondragstart="dragStart(event)">
</div>
<div id="box3" ondrop="dragDrop(event)"
ondragover="allowDrop(event)">
</div>
</div>
</body>
</html>
说明:
效果:
lement Plus 的弹窗组件 ElDialog 在默认情况下是不可拖拽和全屏的。要实现这两个功能,可以通过以下方式:
实现拖拽
实现全屏
这样就可以实现 Element Plus 的 ElDialog 组件拖拽和全屏功能。更多 CSS 样式可以根据需求自定义。
通过组合 Composition API,可以灵活扩展组件的功能,如拖拽、全屏、自定义关闭逻辑等, making Element Plus 更易用。
最终实现效果如下:
<script src="https://lf3-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
效果图:
演示地址:Vue Shop Vite
*请认真填写需求信息,我们会在24小时内与您取得联系。