making my own drag and drop effect.

making my own drag and drop effect.

Hi, I am trying to make my own drag and drop effect using just jquery and not jquery.ui

here is the code I have so far:


  1. var x_pos;
  2. var y_pos;
  3. $(document).mousemove(function(rp){
  4. x_pos = rp.pageX;
  5. y_pos = rp.pageY;
  6. });

  7. $("*").mousedown(function(ramskin){
  8. var taz = [id:of element_this line isn't posted...in script it's coded to grab element id that been clicked]; 

  9. if(ramskin.which == '1'){
  10. $(document).mousemove(function(){
  11. $(taz).css({ \"left\": x_pos, \"top\": y_pos  });
  12. $(\"*\").click(function(){
  13. $(document).unbind('mousemove');
  14. $(document).bind('mousemove');
  15. });
  16. });
  17. }
  18. if(ramskin.which == '3'){ 
  19. open a div when clicked.
  20. }
  21. });

I  currently can click on a image and then drag it and then drop it but can't click on it again to drag it.
Plus  if I click  anything else like a div or text  the element would appear far right rather then be right under the users mouse. Why is that???