Drag and Drop using Javascript
Submitted by jaredgwapo on Sunday, January 3, 2016 - 22:44.
Language
In this tutorial, we are going to learn how to the image into the box using javascript. This is a simple project that you can use in your website or system.
Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you.
DIRECTIONS
HTML CODE
JAVASCRIPT CODE
- <script>
- 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>
CSS CODE
- <style>
- #div1 {width:150px;height:150px;padding:10px;border:1px solid #aaaaaa;}
- #left
- {
- border: 1px solid #aaaa;
- width: 200px;
- float: left
- }
- #right
- {
- border: 1px solid #aaaa;
- width: 200px;
- float: right;
- }
- #container
- {
- width: 580px;
- margin: auto;
- }
- p
- {
- font-size: 25px;
- text-align: center;
- }
- </style>
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 125 views