it looks to me that all tutorial about html drag and drop set the onmousedown and onmouseup events to the document rather than the element itself, and as i tested with below codes, when clicking the element, both the onmousedown and onmouseup event will be triggered, but when try to drag the element and drop it at another place, the onmouseup event is not fired,
I use below codes, my question is: why onmouseup is not fired when dragging? I use firefox 8.0.1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Border</title>
<style type="text/css">
body{
background-color: gray;
}
#page{
margin: 20px auto;
width:800px;
height:639px;
/*background-image: url("./img/board.jpg");*/
background-image: url("https://www.google.com/logos/2012/dickens-2012-HP.jpg");
background-repeat: no-repeat;
}
#target{
position: relative;
top: 10px;
left: 20px;
/*background-image: url("./img/target.jpg");*/
background-image: url("https://www.google.com/images/icons/product/chrome-48.png");
background-repeat: no-repeat;
width: 145px;
height:117px;
}
</style>
<script type="text/javascript">
function mylog(msg)
{
if(window.console && console.log){
console.log(msg);
}
}
window.onload = function(){
initdragdrop();
}
/*
todo: learn how to make a getObject()
function getObject(id){
var t = document.getElementById(id);
this.x = t.left;
this.y = t.top;
}
*/
function initdragdrop(){
var t = document.getElementById('target');
t.onmousedown = function(){
this.status = 'down';
mylog(this.status);
}
t.onmouseup = function(){
this.status = 'up';
mylog(this.status);
}
}
</script>
</head>
<body>
<div id="page">
<div id="target">
</div>
</div>
</body>
</html>