/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Mouse position = always frustrating…

Hello, i cant seem to figure out this even though i have before :S

Im making a drag n drop script and want the object im dragging to be dragged from the point relative to where the mouse is positioned on the element.

I though this should be somewhat the way to calculate it, but this wont move the element one pixel. If i put + 1 right before + ‘px’ it moves, but not correctly since it will increment 1 extra pixel every mouse movement. Please can anyone check it out? (this is only the relevant piece of code….)

[CODE]
this.onmousemove = function(e) {
e = dsDyn.drag.fixE(e);
this.style.left = e.clientX – (e.clientX – target.offsetLeft) + ‘px’;
this.style.top = e.clientY – (e.clienty – target.offsetTop) + ‘px’;
}
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ReisauthorNov 15.2009 — Solved
Copy linkTweet thisAlerts:
@ReisauthorNov 16.2009 — I figured it out ?
×

Success!

Help @Reis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...