Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Drag - not catching my mouse events

    Just registered, because I'm trying to figure out some dragging stuff and it's not working the way I'd like and I really can't figure out why.

    I made a drag element (image). I just want to apply the code to this element.

    This is what happens:
    1. I click on the image
    2. I hold the mouse down and drag
    => the element don't follow
    3. I let go of the mouse button
    => the element gets dragged
    4. I click again
    => the element stops dragging

    This is what I would like to happen (obviously):
    1. I click the image
    2. Hold the mouse down and drag
    => element follows
    3. Mouse up
    => element stops following

    var dragSko;
    var dragSkoUrsp;
    document.onmousedown = startaKod;
    document.onmouseup = musUpp;
    function startaKod(e) {
    	if (e.target.id == 'dragsko') {
    	startX = e.clientX;
    	dragSkoUrsp = parseInt(e.target.style.left);
    	document.onmousemove = musFlyttDrag;
    	dragSko = e.target
    	function musFlyttDrag(e) {
    		dragsko.style.left = (dragSkoUrsp + e.clientX - startX) + 'px' ;
    function musUpp(e) {
    		document.onmousemove = null;
    I'd very much appriciate if some kind soul had a look and explained what I've done wrong.
    Last edited by LottenW; Dec 8th, 2011 at 06:57 PM. Reason: clearify

  2. #2
    New to the CF scene
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts
    Was a problem on another place in the code.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts