Purchase Advertising On AWT
 Upload & Sell Your Software
 Upload & Sell Your eBook
 Enter The AWT Control Panel  Contact Applied Web Tools
 Sell Your eBook @ The PDF Store  Password Troubles? Click Here!
Knowledge Center
Want to write for Applied Web Tools? Send your Writer's Query to
Editor@AppliedWebTools.net for details.
HTML
Reference
&
Tutorial
CSS
Reference
&
Tutorial
DOM
Reference
&
Tutorial
JavaScript
Reference
&
Tutorial
50+ Programming Examples
Use HTML, CSS, DOM & JavaScript Together
Misc. Essays & Documents
You'll Find Just About Anything In Here
50+ Web Page Constructions
Learn the Art of Using HTML, CSS, DOM & JavaScript Together
 Changing Background Colors
 Event Triggering With onLoad
 Disabling The Right Click
 DOM Driven Color Changing
 Switching Images
 innerHTML Attribute Access
 Change With innerHTML
 Changing Positions
 Change Position With onMouseMove
 Change Text Position
 Interactivity Skills
 Type-writing A Message
 Auto-changing Text Size
 Making Text Scroll
 Blinking Text
 Simple Form Authentication
 Change Background Color Of An INPUT
 Change Text Color Of An INPUT
 Change Background Image Of An INPUT
 Select All Checkboxes
 Select Color Of The Submit Button
 Change Text Color Of A Submit Button
 Insert Background Image To A Button
 Change Color Of Drop Down List
 Change Text Color Of A Drop Down List
 Change Color Of A TEXTAREA
 Change The Text Color Of A TEXTAREA
 Insert An Image Into A TEXTAREA
 Change The Size Of An Image
 Change The Source Of An Image
 Change The Position Of An Image
 Change The Background Image
 Moving Images Around The Page
 Drag & Drop An Image
 A Simple Image Viewer
 A Shaking Image
 A Digital Clock
 Drop Down List Link
 Top Drop Down Menu
 Always On Top Menu
 Inset Border Buttons
 A Description Generating Menu
 An Image Generating Menu
 A Horizontal Sliding Menu
 A Click Horizontal Sliding Menu
 Returning Cursor Co-ordinates
 Making Text Follow The Cursor
 Attaching An Image To The Cursor
drag and drop an image

Some of the higher functions of a web page can be very simple to implement. Dragging and dropping an image into a new location can be very a handy method of increasing production. We first start with an absolutely positioned image placed in the usual way within the document. We then read the co-ordinates of the image and keep reading those co-ordinates as the image is dragged and dropped. The last last co-ordinates of the image are read and an action is assigned if the co-ordinates are within a range you specify, such as the location of a different section within a larger table.

A function is triggered with the onMouseDown event handler and the image is released from its positioning constraints. Upon the execution of an onMouseUp event, the new position is read and the image is repositioned elsewhere. You can assign scripted actions according to where the image was last placed (dropped).

<html>
<head>

<style>
Img {position:absolute; }
</style>

<script type="text/javascript">
document.onmousedown=coordinates;
document.onmouseup=mouseup;

function coordinates(e) {

if (e == null) { e = window.event;}
var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target;

if (sender.id=="moveMe") {
mouseover=true;
pleft=parseInt(movMeId.style.left);
ptop=parseInt(movMeId.style.top);
xcoor=e.clientX;
ycoor=e.clientY;
document.onmousemove=moveImage;
return false;
} else {
return false;
}
}

function moveImage(e) {
if (e == null) {
e = window.event;
}
movMeId.style.left=pleft+e.clientX-xcoor+"px";
movMeId.style.top=ptop+e.clientY-ycoor+"px";
return false;
}

function mouseup(e) {
document.onmousemove=null;
}
</script>

</head>

<body>

<img id="moveMe" src="smiley.gif" width="32" height="32">

<script type="text/javascript">
//The movable image
movMeId=document.getElementById("moveMe");
//image starting location
movMeId.style.top="75px";
movMeId.style.left="75px";
</script>

</body>
</html>


Note that the start position of the image is stated within SCRIPT tags near the bottom of the document. This can be anywhere within the document and is the start values that will be altered as the image is moved. We used both the X and Y axis co-ordinates, but this isn’t required if you’d like to keep the images in line vertically or horizontally. If you use this method, the user doesn’t actually have to keep the image being repositioned within the line of vertical or horizontal space – the browser will record only the X or Y axis co-ordinates regardless of the other co-ordinate that the image is actually travelling on.
I do not employ cookies or tracking devices of any kind