It's quite straightforward really: In the dragstart event calculate the offset between where the user clicked on the draggable element and the top left corner Make sure the dragover event is applied to the entire document so the element can be dropped anywhere In the drop event, use the offset you calculated with the clientX and clientY of the drop to work out where to position the element Here's one I prepared earlier. For bonus points you can update the top and left position of the element in the dragover event, this is useful if the bit you're allowing to be dragged isn't the whole element that needs to be moved.
Drag and drop doesn't move elements around, if you want the element to move when you drop it then you have to set the new position of the element in the drop event. I've done an example which works in Firefox and Chrome, here are the key points.
Drag and drop doesn't move elements around, if you want the element to move when you drop it then you have to set the new position of the element in the drop event. I've done an example which works in Firefox and Chrome, here are the key points: function drag_start(event) { var style = window. GetComputedStyle(event.
Target, null); event.dataTransfer. SetData("text/plain", (parseInt(style. GetPropertyValue("left"),10) - event.
ClientX) + ',' + (parseInt(style. GetPropertyValue("top"),10) - event. ClientY)); } The dragstart event works out the offset of the mouse pointer from the left and top of the element and passes it in the dataTransfer.
I'm not worrying about passing the ID because there's only one draggable element on the page - no links or images - if you have any of that stuff on your page then you'll have to do a little more work here. Function drop(event) { var offset = event.dataTransfer. GetData("text/plain").
Split(','); var dm = document. GetElementById('dragme'); dm.style. Left = (event.
ClientX + parseInt(offset0,10)) + 'px'; dm.style. Top = (event. ClientY + parseInt(offset1,10)) + 'px'; event.preventDefault(); return false; } The drop event unpacks the offsets and uses them to position the element relative to the mouse pointer.
The dragover event just needs to preventDefault when anything is dragged over. Again, if there is anything else draggable on the page you might need to do something more complex here: function drag_over(event) { event.preventDefault(); return false; } So bind it to the document. Body along with the drop event to capture everything: var dm = document.
GetElementById('dragme'); dm. AddEventListener('dragstart',drag_start,false); document.body. AddEventListener('dragover',drag_over,false); document.body.
AddEventListener('drop',drop,false); If you want this to work in IE you'll need to convert the aside to an a element, and, of course, all the event binding code will be different. The drag and drop API doesn't work in Opera, or on any mobile browsers as far as I'm aware. Also, I know you said you don't want to use jQuery, but cross browser event binding and manipulating element positions are the sort of things that jQuery makes much easier.
I wish I could promote this answer more - this was exactly what I was looking for. Thank you. – clicheName Jun 5 at 3:02.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.