event.offsetX in Firefox

后端 未结 11 1819
既然无缘
既然无缘 2020-11-27 16:45





        
11条回答
  •  时光取名叫无心
    2020-11-27 17:12

    offset actually doesn't translate directly into layer; the offset property doesn't account for the element's margin. The code below should account for this.

    function(e) {
        var x = e.offsetX, y = e.offsetY;
        if(e.hasOwnProperty('layerX')) {
          x = e.layerX - e.currentTarget.offsetLeft;
          y = e.layerY - e.currentTarget.offsetTop;
        }
    }
    

提交回复
热议问题