view src/examples/dropzones.html @ 11:80ef70ca5860

add onStart
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 11 May 2023 14:37:10 -0600
parents 4d699321068f
children
line wrap: on
line source

<!doctype html>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<style>
			@import "/site.css";
			@import "/dad.css";

			[drag] {
				display: inline-block;
				background-color: LightGreen;
				padding: 8px;
			}
			[dropzone] {
				background-color: LightBlue;
				padding: 8px;
			}
			[dropzone][in] {
				border: 1px solid;
			}
		</style>
		<script src="/dad.js"></script>
		<script>
			dad.onEnter = function(event) {
				event.dropzone.setAttribute('in','');
			};

			dad.onLeave = function(event) {
				event.dropzone.removeAttribute('in');
			};

			dad.onDrop = function(event) {
				if( event.dropzone )
					event.dropzone.appendChild(event.original);
			};

			function init() {
				let drag = document.querySelector('[drag]');
				dad.setDraggable(drag);
				let dropzones = document.querySelectorAll('[dropzone]');
				for( let i=0; i<dropzones.length; i++ ) {
					let dropzone = dropzones[i];
					dad.setDropzone(dropzone);
				}
			}
		</script>
	</head>
	<body>
		<h1>Dropzones</h1>
		<p dropzone>dropzone 1 <span drag>drag me</span></p>
		<p dropzone>dropzone 2 </p>
		<p dropzone>dropzone 3 </p>
		<p>bottom</p>
	</body>
	<script> init(); </script>
</html>