range-at-xy

0.0.1 • Public • Published

range-at-xy

Given an HTMLElement and a pair of coordinates x and y, returns a Range object, containing the text character visible at position (x, y).

If no character is visible at position (x, y), null is returned.

Important: Coordinates must be provided on the viewport coordinate system. (i.e. e.clientX and e.clientY)

example

var atxy = require('range-at-xy');
 
document.body.addEventListener('mousemove', function() {
  var range = atxy(document.body, e.clientX, e.clientY);
  if (range) {
    // print character under cursor
    console.log(range.cloneContents().textContent);
  }
})

/range-at-xy/

    Package Sidebar

    Install

    npm i range-at-xy

    Weekly Downloads

    2

    Version

    0.0.1

    License

    none

    Last publish

    Collaborators

    • coreh