I wanna make a jquery function that "follow the div when it is on mousedown" - So the div on my page follows the cursor, as the mouse moves, when the mouse button is down.
and when the mouse button is up the div stay in the last position the mouse down was.
<script src="jquery-2.0.3.min.js"></script>
<script>
var posX, posY;
$(document).on('click', mueve);
function mueve (e) {
posX = e.pageX - 20;
posY = e.pageY - 20;
$('.item').animate({left: posX, top: posY})
}
</script>
css:
.item{
background: #bbb;
height: 40px;
width: 40px;
position: absolute;
border-radius: 50%;
left: 0;
top: 0;
}