View Single Post
Eski 18/09/2007, 21:45   #4 (permalink)
Sniper
Üye
 
Sniper Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 06/2004
Yer: İstanbul
Mesaj: 2,327
Varsayılan

document nesnesinin elementFromPoint metodu tam istediğiniz şey fakat Firefox'ta çalışmadığı için internetten bulduğum bir kaynakla ek yapmak suretiyle Firefox'un da aynı metoda destek vermesini sağlayarak bu sorunu aştım:

Kod:
<SCRIPT>
// Program:      document.elementFromPoint(int clientX, int clientY) in Gecko
// Author:       Jason Karl Davis (www.jasonkarldavis.com)
// Date:         15 June 2003
// Purpose:      Emulate Internet Explorer's document.elementFromPoint method as described here:
//               http://msdn.microsoft.com/workshop/a...tfrompoint.asp
// Requirements: A browser built off of the 1.4 branch of Mozilla (or better)
// Distribution: You may freely distribute and use this script as long as these comments remain intact

if (navigator.product == "Gecko") {
 Document.prototype.elementFromPoint = function(x, y) {
  this.addEventListener("mousemove", this.elementFromPoint__handler, false);
  var event = this.createEvent("MouseEvents");
  var box = this.getBoxObjectFor(this.documentElement);
  var screenDelta = { x: box.screenX, y: box.screenY };
  event.initMouseEvent("mousemove", true, false, this.defaultView, 0,
                        x + screenDelta.x, y + screenDelta.y, x, y,
                        false, false, false, false, 0, null);
  this.dispatchEvent(event);
  this.removeEventListener("mousemove", this.elementFromPoint__handler, false);
  return this.elementFromPoint__target;
 }
 Document.prototype.elementFromPoint__handler = function (event) {
  this.elementFromPoint__target = event.explicitOriginalTarget;
 
  // reparent target if it is a text node to emulate IE's behavior
  if (this.elementFromPoint__target.nodeType == Node.TEXT_NODE)
   this.elementFromPoint__target = this.elementFromPoint__target.parentNode;
 
  // change an HTML target to a BODY target to emulate IE's behavior (if we are in an HTML document)
  if (this.elementFromPoint__target.nodeName.toUpperCase() == "HTML" && this.documentElement.nodeName.toUpperCase() == "HTML")
   this.elementFromPoint__target = this.getElementsByTagName("BODY").item(0);

  event.preventDefault();
  event.stopPropagation();
 }
 Document.prototype.elementFromPoint__target = null;
}

function hangiElemanaTiklanmis(e){
   spanTo.innerHTML=document.elementFromPoint(e.x, e.y).tagName;
}

</SCRIPT>
:
<SPAN onclick="hangiElemanaTiklanmis(event)">
   <P>Mouse Over This</P>
   <P>toElement: <SPAN ID="spanTo"></SPAN></P>
</SPAN>
__________________
tuncay.kinali.net
Sniper hatta değil   Alıntı Yaparak Yanıtla