DKP Posted July 17, 2009 Share Posted July 17, 2009 I've got some HTML elements that I want to be able to drag around my page. I've created a div for each item w/ a background image and have written the javascript code to maintain the offset relative to the mouse after an item is selected to give the appearance of "dragging". All this actually works fine, at least some of the time.The problem that I'm having is that probably 50% of the time when I click on one of the items, the browser throws up the circle w/ a slash through it cursor and bypasses my drag code. I see this same behavior (the cursor popping up) on a normal web page if I try to click and drag an normal image that's not a link. So it would appear that sometimes the browser thinks I'm actually trying to click and drag the image instead of clicking and dragging the div.Is there anyway in JavaScript to ensure that the right event handlers are getting called so that the browser doesn't confuse what I'm trying to do? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 17, 2009 Share Posted July 17, 2009 Look up event propagation, that's the difference between the event bubbling or cascading. Or, you can use a pre-made drag and drop library. Walter Zorn has a good one:http://www.walterzorn.com/dragdrop/dragdrop_e.htm Link to comment Share on other sites More sharing options...
DKP Posted July 17, 2009 Author Share Posted July 17, 2009 Actually after further testing it appears as if it only occurs when you click the same item two times consecutively. So the first time I click item 1 it works. If after I let go I immediately click the same item again I get the problem, but if I click another item and then go back to number 1 its fine. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.