javascript - document.elementFromPoint returning null on IE -
i using document.elementfrompoint getting selected element dragging it. returns null. when debug same , re run same code, object returned.
following code:
function getzonefrompoint(x, y, prtdrag, elemibeam,evnt) { if (x == null || y == null || prtdrag == null || elemibeam == null) alert("null in getzone"); var prtdragzindexold = prtdrag.style.zindex; var elemibeamzindexold = elemibeam.style.zindex; prtdrag.style.zindex = -1; elemibeam.style.zindex = -1; var zone; zone = document.elementfrompoint(x, y); prtdrag.style.zindex = prtdragzindexold; elemibeam.style.zindex = elemibeamzindexold; if (zone == null) { zone = document.elementfrompoint(x, y); if (zone == null) { debugger; zone = event.rangeparent; } } if (zone == null) { alert('null'); return null; } if (x < 0 || x > document.body.clientwidth || y < 0 || y > document.body.clientheight) { zone = null; } else if ((zone.classname == 'layoutwellelement') || (zone.classname == 'layoutmainelement') || (zone.classname == 'elementframe')) { while ((!fiszone(zone)) && (zone.tagname != 'body')) { zone = zone.parentelement; } } if (!fiszone(zone)) { zone = null; } return zone; }
it's have same nasty idea, haha. i'm working on object collision. look, call getzonefrompoint. cursor click event invoked in browser, right? so, no need check x or y, zone=null @ first. double check elementfrompoint while x & y unchanged? i'm done work flow here.
some tips: - have 2 'absolute' div objects called & b b overlap @ bottom right corner. - use this: var x=parseint(b.offsetleft); var y=parseint(b.offsettop); alert(document.elementfrompoint(x,y).innerhtml); - why parse? offsetleft return in format: number+"px" - result is: ie->return while ff->b - if x-1 or y-1, both browsers return a. - final words: don't use document.body.clientwidth alone check resolution, try document.body.clientwidth-o.clientwidth. hope these give power bonus. cheer!
Comments
Post a Comment