我有一个红色正方形div,位置是绝对的.
但它不允许在其周围的背景中 Select 文本.
Html
个
<!DOCTYPE html>
<html lang="en">
<head>
<title>React App</title>
</head>
<body>
<div>You need to enable JavaScript to
...more text..check example,,,...to run this app.You need to
enable JavaScript to run this app.
You need to enable JavaScript to run this app.</div>
</body>
</html>
JS
个
var mousePosition;
var offset = [0,0];
var div;
var isDown = false;
div = document.createElement("div");
div.style.position = "absolute";
div.style.left = "100px";
div.style.top = "100px";
div.style.width = "100px";
div.style.height = "100px";
div.style.background = "red";
div.style.color = "blue";
document.body.appendChild(div);
div.addEventListener('mousedown', function(e) {
isDown = true;
offset = [
div.offsetLeft - e.clientX,
div.offsetTop - e.clientY
];
}, true);
document.addEventListener('mouseup', function() {
isDown = false;
}, true);
document.addEventListener('mousemove', function(event) {
event.preventDefault();
if (isDown) {
mousePosition = {
x : event.clientX,
y : event.clientY
};
div.style.left = (mousePosition.x + offset[0]) + 'px';
div.style.top = (mousePosition.y + offset[1]) + 'px';
}
}, true);
我不想使用z-index属性.
你知道怎么做吗?我只想 Select 红色方块周围的文本,而不是方块下面的文本.提前谢谢你