插件基于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+"http://"+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小時內與您取得聯系。