Home Web Front-end H5 Tutorial HTML5 actual combat and analysis of native drag and drop (an overview of drag and drop history)

HTML5 actual combat and analysis of native drag and drop (an overview of drag and drop history)

Feb 11, 2017 am 11:39 AM


When I mention drag and drop, I think of a very interesting effect during JavaScript training, which is drag and drop. You can use the mouse to drag an object anywhere you want.

The first browser to have JavaScript drag and drop functionality was IE4. At that time, there were only two types of objects on the web page that could be dragged and dropped: graphics and certain text. When dragging an image, place the mouse on the image and hold down the mouse to drag. When dragging text, you must first select the text, and then drag the selected text like an image. In IE4, the only valid target for placing dragged text is a text box. With IE5.5, it goes a step further, allowing any element in the web page to be dragged and dropped (IE6 and above also support these functions). With the gradual updating of browsers, and the birth of IE7IE8 and other browsers, everything on the webpage can be dragged and dropped, but it is only implemented through JavaScript programs. The following is a small example of drag and drop implementation when there is no HTML5.

 HTML code

<p id="p1" style="width:100px; height:100px; background:red; position:absolute;">梦龙小站</p>
Copy after login


 JavaScript code

window.onload = function(){
	var op = document.getElementById(&#39;p1&#39;);
	var disX = 0;
	var disY = 0;
	
	op.onmousedown = function(ev){
		var ev = ev || window.event;
		disX = ev.clientX - op.offsetLeft;
		disY = ev.clientY - op.offsetTop;
		
		//在IE下,如果选中元素拖拽就会有问题 : IE设置全局捕获:setCapture 释放全局捕获:releaseCapture
		if(op.setCapture){
			op.setCapture();
		}
		
		document.onmousemove = function(ev){
			var ev = ev || window.event;
			op.style.left = ev.clientX - disX + &#39;px&#39;;
			op.style.top = ev.clientY - disY + &#39;px&#39;;
		};
		
		document.onmouseup = function(){
			document.onmousemove = null;
			document.onmouseup = null;
			if(op.releaseCapture){
				op.releaseCapture();
			}
		};

		//在标准浏览器下如果拖拽一个空的标签,就会有问题 : return false
		//在标准浏览器下拖拽图片会有问题:return false
		return false;
	};
	
};
Copy after login


 CSS code

li{ width:100px; height:30px; border:1px #000000 solid; margin:20px; list-style:none;}
#p1{ width:100px; height:100px; background:red; margin:300px;}
Copy after login

Until the emergence of HTML5. HTML5 is a drag-and-drop specification based on IE. Browsers that support native drag and drop include: Chrome, Safari 3+ and Firefox 3.5+.

 Drag and drop in HTML5 can be perfectly dragged between windows, between frames, and even between applications. Browser support for drag and drop facilitates this functionality.

HTML5 actual combat and analysis of native drag (1) - an overview of drag and drop history, that’s it for everyone. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!









#

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles