Well, no magic tricks so far, so here is a boring boring (and yet working) solution:
$(document.body).mousemove(function(e){
var onmousestop = function() {
function getHitWord(hit_elem) {
var hit_word = '';
hit_elem = $(hit_elem);
var text_nodes = hit_elem.contents().filter(function(){
return this.nodeType == Node.TEXT_NODE && this.nodeValue.match(/[a-zA-Z]{2,}/)
});
if (text_nodes.length > 0) {
var original_content = hit_elem.clone();
text_nodes.replaceWith(function(i) {
return $(this).text().replace(/([a-zA-Z-]*)/g, "<word>$1</word>")
});
var hit_word_elem = document.elementFromPoint(e.clientX, e.clientY);
if (hit_word_elem.nodeName != 'WORD') {
console.log("missed!");
}
else {
hit_word = $(hit_word_elem).text();
console.log("got it: "+hit_word);
}
hit_elem.replaceWith(original_content);
}
return hit_word;
}
var hit_word = getHitWord(document.elementFromPoint(e.clientX, e.clientY));
...
}
}
There are a few other subtleties (like “noise reduction,” preserving dom substitution (like choosing), etc.), but you get the idea.
Here you can learn how to set up the mousestop event.
EDIT:
Creating custom html elements might not be such a breakthrough in IE (who would have thought?). More details here .
source
share