Drag event editor implements drag and drop upload image effect
This time I will bring you the Drag eventEditorTo realize the effect of dragging and uploading pictures, what are the things to notein the Drag event editor to realize the effect of dragging and uploading pictures, the following are Let’s take a look at practical cases.
The editor image upload of this site is used to upload this partSeajs definition Tools module/** * Created by zhaojunlike on 8/22/2017. */ define(function (require, exports, module) { /** * 截图粘贴 * @param selector * @param callback */ exports.paste = function (selector, callback) { document.querySelector(selector).addEventListener("paste", function (ev) { var data = ev.clipboardData; var items = (event.clipboardData || event.originalEvent.clipboardData).items; for (var i in items) { var item = items[i]; //如果是图片 if (item.kind === 'file' && item.type.indexOf('image') > -1) { var blob = item.getAsFile(); var reader = new FileReader(); //reader读取完成后,xhr上传 reader.onload = function (event) { var base64 = event.target.result; //ajax上传图片 //返回一个base64数据 var img = {type: item.type, kind: item.kind}; if (typeof callback === "function") { callback(event.target.result, img, event); } }; // data url! reader.readAsDataURL(blob);//reader } } }); }; /** * 拖拽上传 * @param selector * @param callback */ exports.drag = function (selector, callback) { var element = document.querySelector(selector); element.addEventListener("drop", function (e) { e.preventDefault(); var files = e.dataTransfer.files; for (var i = 0; i < files.length; i++) { //回调文件 //alert("Drop " + file[i].name.toString()); var reader = new FileReader(); var item = files[i]; reader.onload = function (event) { var base64 = event.target.result; //返回一个base64数据 var img = {type: item.type, name: item.name}; if (typeof callback === "function") { callback(event.target.result, img, event); } }; reader.readAsDataURL(files[i]);//reader } return false; }); element.addEventListener("dragenter", function (e) { e.stopPropagation(); e.preventDefault(); }); element.addEventListener("dragover", function (e) { e.dataTransfer.dropEffect = "copy"; e.stopPropagation(); e.preventDefault(); }); document.body.addEventListener("dragover", function (e) { e.stopPropagation(); e.preventDefault(); return false; }); } /** * 解析粘贴过来的内容,看是否有不是本站的图片,解析出来上传到本站 */ exports.parseImg = function () { } });
//粘贴上传图片 Edtools.paste("#post_content", function (base64, image, event) { $.post("{:url('api/uploader/upEditorImg')}",{base:base64}, function (ret) { layer.msg(ret.msg); if (ret.code === 1) { //新一行的图片显示 editor.insertValue("\n"); } }); }); //拖拽上传图片 Edtools.drag("#post_content", function (base64, image, event) { $.post("{:url('api/uploader/upEditorImg')}",{base:base64}, function (ret) { layer.msg(ret.msg); if (ret.code === 1) { //新一行的图片显示 editor.insertValue("\n"); } }); });
Detailed explanation of the use of H5's LocalStorage local storage
Customized implementation can play, pause, and progress drag and drop , volume control and full-screen H5 player
The above is the detailed content of Drag event editor implements drag and drop upload image effect. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Have you ever faced any issues while transferring files that prevented you from doing so? Well, many Windows users have recently reported that they faced issues while copying and pasting files into a folder, where an error was thrown saying “The file name of the destination folder is too long”. Additionally, some other Windows users expressed frustration when opening any file and said "the file name or extension is too long" and they were unable to open the file. This disappoints users by not allowing them to transfer files to any other folder. While analyzing the issue, we have come up with a series of solutions that may help alleviate the issue and allow users to transfer files easily. If you are in a similar situation, please see this post for more information. Source: https

There is no better way to write Python code than using an integrated development environment (IDE). Not only can they make your work simpler and more logical, they can also improve programming experience and efficiency. Everyone knows this. The question is, how to choose the best Python development environment among the many options.

Many Windows users have recently reported that they were annoyed when Windows Defender SmartScreen warned users not to launch applications that were not recognized by Microsoft Windows and they had to click on the "Run anyway" option every time. Windows users are unsure what they can currently do to avoid or disable it. After researching the issue, we found that Windows Defender functionality on the system can be disabled through the Settings application or the Local Group Policy Editor or by adjusting the registry files. By doing this, users will no longer have to face the defender SmartScreen. If your system also encounters

How to implement file upload and processing in FastAPI FastAPI is a modern, high-performance web framework that is easy to use and powerful. It provides native support for file upload and processing. In this article, we will learn how to implement file upload and processing functions in the FastAPI framework, and provide code examples to illustrate specific implementation steps. First, we need to import the required libraries and modules: fromfastapiimportFastAPI,UploadF

C language is a basic and important programming language. For beginners, it is very important to choose appropriate programming software. There are many different C programming software options on the market, but for beginners, it can be a bit confusing to choose which one is right for you. This article will recommend five C language programming software to beginners to help them get started quickly and improve their programming skills. Dev-C++Dev-C++ is a free and open source integrated development environment (IDE), especially suitable for beginners. It is simple and easy to use, integrating editor,

How to solve the slow upload speed of Win10 computer? When we use the computer, we may feel that the file upload speed of our computer is very slow. So what is the situation? In fact, this is because the default upload speed of the computer is 20%, so the upload speed is very slow. Many friends do not know how to operate in detail. The editor has compiled the steps to format the C drive in Win11 below. If you are interested, follow Let’s take a look below! Solution to the slow upload speed of Win10 1. Press win+R to call up run, enter gpedit.msc, and press Enter. 2. Select the management template, click Network--Qos Packet Scheduler, and double-click Limit to reserve bandwidth. 3. Select Enabled, which will bring

With the advent of the digital age, music platforms have become one of the main ways for people to obtain music. However, sometimes when we listen to songs, we find that there are no lyrics, which is very disturbing. Many people hope that lyrics can be displayed when listening to songs to better understand the content and emotions of the songs. QQ Music, as one of the largest music platforms in China, also provides users with the function of uploading lyrics, so that users can better enjoy music and feel the connotation of the songs. The following will introduce how to upload lyrics on QQ Music. first

1. Open Kugou Music and click on your profile picture. 2. Click the settings icon in the upper right corner. 3. Click [Upload Music Works]. 4. Click [Upload Works]. 5. Select the song and click [Next]. 6. Finally, click [Upload].
