Home >Web Front-end >HTML Tutorial >The complete code for implementing drag in html

The complete code for implementing drag in html

不言
不言Original
2018-08-30 11:39:432052browse

The content of this article is about the analysis of the causes of flat floating in CSS and the problems it brings. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>drag</title>
	<style type="text/css">
		#p1{
			width :100px; 
			height :30px;
			border:1px solid red; 
		}
	</style>

	<script type="text/javascript">
	function allowDrop(ev){
		ev.preventDefault();
	}

	function drag(ev){
		ev.dataTransfer.setData("Text",ev.target.id);
	}

	function drop(ev){
		ev.preventDefault();
		var data = ev.dataTransfer.getData("Text");
		ev.target.appendChild(document.getElementById(data));
	}
	</script>
</head>
<body>
	<p id="p1" ondrop="drop(event)" ondragover="allowDrop(event)"></p>
	<br>
	<p id="drag1" draggable="true" ondragstart="drag(event)" >鎷栧姩</p>
</body>
</html>

Related recommendations:

html drag animation implementation method

Drag an HTML element_javascript skills

The above is the detailed content of The complete code for implementing drag in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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