I have a HTML webpage that contains a 15x15 table and I also have a small square div that follows the mouse when you press and hold the left mouse button on the div.
I have assigned an onmouseover event to the 15x15 table so that when the mouse hovers over a cell, a variable called "gridPlacement" is set the value of the unique id of the table cell the mouse hovered over.
The onmouseover event seems to work fine and instantly as soon as you hover over a cell the variable "gridPlacement" is set to the cell's id.
But when the onmousedown and onmousemove events are triggered (when the mouse presses and holds the left mouse button on the div I mentioned earlier), sometimes when you hover over a cell the variable "gridPlacement" isn't set, and sometimes you have to move your mouse over the cell a few times for it to work.
It seems the onmousedo开发者_Python百科wn and onmousemove events seem to have an impact on the onhover event on my 15x15 table.
Does anybody know why this happens and how I can work around this problem?
I hope you understand me, I've tried to explain my problem as best as I can.
PROBLEM SOLVED!
Changing the offset of the element the user is dragging did the trick, thank you all for helping me! :)
I think zozo is correct. I ran into a similar problem and the workaround I used is to change the offset of the element following the mouse so that it does not appear directly under the mouse (maybe a few pixels to the side/above/below or something).
Hope this helps.
The problem you asked about happens because when you have the button pressed the div is under your mouse, so you don't actually hover the cell (at least thats what I get from your description). A workaround would be to set the desired variable when you exit a certain cell (onmouseout) but this does not help you since I guess you want to know over witch cell you are over, so I guess you can get the mouse position and compare it to the position of the cells... unless you get a better answer because this is kind of... not so easy.
精彩评论