Jump to content

problem with dragging script


Skizo
 Share

Recommended Posts

http://jsfiddle.net/fDcZS/486/I saw this dragging script on the internet but the code has 2 problems.1. If you drag the square and drag it again something strange happens, i cant explain it..2. In google chrome if you're dragging the square the mouse cursor is changing to the text cursor(only when you're dragging).In IE it works fine.Is there a solution? Edited by Skizo
Link to comment
Share on other sites

to fix the shape from being centered to the mouse position, you could store the mouse-to-shape xy position offsets:

function startMove() {$('.movable').on('mousemove', function(event) {var thisX = event.pageX + offsets.x,thisY = event.pageY + offsets.y; $('.movable').offset({left: thisX,top: thisY});});}$("#containerDiv").on('mousedown', function(event) {$(this).addClass('movable');offsets = {x: $(this).offset().left - event.pageX,y: $(this).offset().top - event.pageY};startMove();}).on('mouseup', function() {$(this).removeClass('movable');});

also check here for the cursor icon:http://stackoverflow...-with-css-or-js

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...