Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Demo: http://jsfiddle.net/H45uY/6/
What I'm trying to do here is make the top-left corner of the <div> follow the mouse. The code works fine without the paragraph (see demo above), but when you add a paragraph, the <div> is pushed up and the mouse is halfway down the side of the box. Why does the paragraph do this?
Thanks!

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

If you remove - offset.top and - offset.left it works in every position

Fiddle Demo

share|improve this answer
add comment

add top:0 and left:0 to the div style

share|improve this answer
 
It works now! Thanks! –  Abraham Sep 6 '11 at 13:54
add comment

You dont need to subtract the offset.

$div.css({
    top:event.pageY,
    left:event.pageX
})

This will put the box at the mouse position.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.