


Examples of operations such as moving, cutting, and copying imitated window folders using js and jq
Window's operations on folders mainly include moving/cut/copying. This article mainly uses jQuery to implement it. Let's learn about it together. This article mainly introduces js/jq imitation window folder movement/cut/copy and other operation codes. It is of great practical value and friends in need can refer to it. Hope it helps everyone.
1. Let’s take a look at the effect first!
2. Add an index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="./jquery-1.12.4.min.js"></script> </head> <style> ul{list-style: none;min-height: 100px;min-width: 100px;background: #eee;} li{width:200px;margin:10px;float:left;height: 200px;background: #ccc;border: 1px solid #fff;overflow: hidden} .selected{border: 1px solid red} </style> <body> <ul class="test-box"> <p style="clear: both"></p> </ul> <ul class='clearfix test' > <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <li><img src="/static/imghwm/default1.png" data-src="./defaultlogo.jpg" class="lazy" alt=""></li> <p style="clear: both"></p> </ul> </body> </html>
3. Add a plug-in
There is an areaSelect.js box selection plug-in in an article, which is used to select the content we want to move. Those who have not read it can go to the previous article and copy it.
Add OptionFile operation object
var OptionFile=(function (opt) { var o={ width:100, // height:100, gapWidth:2 }; var o = $.extend(o,opt), _body=$('body'), boxBg='<p style="position: absolute;height: 100%;width: 100%;background: rgba(225,225,225,1);left: 0;top: 0;z-index: 1"></p>', movingBox='<p class="moving-box" style="width: '+o.width+'px;height: '+o.height+'px;box-sizing:border-box;position: absolute;z-index: 8888;"></p>'; return { actionLock:false, //移动锁定 releaseTarget:false, //释放锁定 keyCode:null, //当前按键 键值 //鼠标按下操作 optionDown:function ( selectFile , type , evt ) { this.releaseTarget=false; this.getImgList(selectFile); var currentX=evt.pageX; var currentY=evt.pageY; $('.moving-box').css({ top:currentY+10, left:currentX+10 }) }, //鼠标移动操作 optionMoving:function (selectFile , type , evt ) { if(this.actionLock){ this.optionDown(selectFile , type , evt ); } }, getImgList:function (selectFile) { var length = selectFile .length, imgWidth = o.width-10-(length)*o.gapWidth, imgHeight = o.height-10-(length)*o.gapWidth; if(!this.actionLock){ _body.append(movingBox); $('.moving-box').append(boxBg); $.each(selectFile,function (k, v) { var img = '<img src="/static/imghwm/default1.png" data-src="'+v.src+'" class="lazy" style="max-width:90%" / alt="Examples of operations such as moving, cutting, and copying imitated window folders using js and jq" >'; $('.moving-box').append(img); }); } this.actionLock=true; }, //放开鼠标操作(回调函数,返回按键键值和当前目标) closeOption:function (func) { var _this= this; $(document).keydown(function (event) { _this.keyCode=event.keyCode; $(document).on('mouseup',function (e) { if(!_this.releaseTarget){ $('.moving-box').remove(); _this.actionLock=false; $(document).unbind('mousemove'); _this.releaseTarget=true; func(e,_this.keyCode); //返回当前 释放的 目标元素 , 和按键code $(document).unbind('keydown'); _this.keyCode=null; } }) }); $(document).trigger("keydown"); $(document).keyup(function (event){ $(document).unbind('keyup'); $(document).unbind('keydown'); _this.keyCode=null; }) } } })
4. Bind functions and operations
$(function () { $(function () { $('.test').areaSelect() //框选操作 }) var optionImg= new OptionFile(); $('.test li').on("mousedown",function(e){ if($(this).hasClass('selected')) { e.preventDefault(); e.stopPropagation(); } var firstImg = $(this).find('img'), currentList=$('.test li.selected img'); //框选的图片list,用于移动的时候显示 currentList.push({src:firstImg.attr('src')}); //移动时候的第一张图片 var loop = setTimeout(function () { optionImg.optionDown(currentList,1,e ); $(document).mousemove(function (e) { optionImg.optionMoving(currentList,1,e); optionImg.closeOption(function (e,keycode) { var target=$(e.target); //目标位置 可以判断目标不同位置执行不同操作 console.log(keycode); //拖拽放开时候是否有按键 keycode 按键的值 可以通过不同的 keycode 来执行不同操作 target.prepend($('.test li.selected')) }); }); },200); $(document).mouseup(function () { clearTimeout(loop); }); }); })
OK ! Now you can see the effect, the plug-in can be expanded and modified by itself.
The above can keycode different key values to complete different operations, such as moving, cutting, copying, pasting, etc. .
Related recommendations:
js to implement imitation window system calendar effect
Imitation windows traversal directory
The above is the detailed content of Examples of operations such as moving, cutting, and copying imitated window folders using js and jq. For more information, please follow other related articles on the PHP Chinese website!

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft