When you create a new contenteditable
<span>
on a page where scale
is used, the keyboard cursor is sometimes put at a wrong position with Firefox.
Example : click on the right side of the window in the following snippet example : the "Strawberry" text will appear, but the I
keyboard cursor will be in a wrong position.
How to have a good I
keyboard cursor position for contenteditable
objects ?
window.onload = function() {
var container = document.createElement("div"),
wrapper = document.createElement("div");
container.style.position = "absolute";
wrapper.style.position = "relative";
container.appendChild(wrapper);
document.body.appendChild(container);
container.style.transform = "scale(0.6)";
zoom = 0.6;
window.onclick = function(e) {
if (e.target.className == 'texte') { return; }
var tb = document.createElement('span');
tb.className = "texte";
tb.contentEditable = true;
tb.style.fontSize = '40px';
tb.style.position = 'absolute';
tb.textContent = 'strawberry';
tb.style.top = e.clientY / zoom + 'px';
tb.style.left = e.clientX / zoom + 'px';
wrapper.appendChild(tb);
tb.focus();
}
}
<!DOCTYPE html>
<html>
<head>
<title>Text map</title>
</head>
<body>
</body>
</html>