最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - text selection on a element behind an absolute element - Stack Overflow

programmeradmin4浏览0评论

I have an overlay element that hides other div's that contains text. the overlay element is absolute positioned. I want the user to be able to select a text on those div's behind. My solution was to hide the overlay (display: none) on user event mouseDown and show it again when the mouseUp event occurred.

that way as soon as the overlay is hidden the user can select the text (as long as the mouseUp hasn't occurred yet).

This solution seems to work on chrome and safari but not on firefox, any advice?

I have an overlay element that hides other div's that contains text. the overlay element is absolute positioned. I want the user to be able to select a text on those div's behind. My solution was to hide the overlay (display: none) on user event mouseDown and show it again when the mouseUp event occurred.

that way as soon as the overlay is hidden the user can select the text (as long as the mouseUp hasn't occurred yet).

This solution seems to work on chrome and safari but not on firefox, any advice?

Share Improve this question asked Apr 17, 2016 at 8:09 DavidDavid 811 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 15

You could use pointer-events on the element you want to click "through":

pointer-events: none;

It may need prefix in some browsers.

Examples: Here without pointer-events: none, you can't select the text:

#outer {
  width: 100px;
  height: 100px;
  display: inline-block;
  border: 1px solid black;
  position: relative;
}
#inner {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  opacity: 0.5;
  background-color: yellow;
}
<div id="outer">
  Testing 1 2 3
  <div id="inner"></div>
</div>

Here with pointer-events: none, you can:

#outer {
  width: 100px;
  height: 100px;
  display: inline-block;
  border: 1px solid black;
  position: relative;
}
#inner {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  opacity: 0.5;
  background-color: yellow;
  pointer-events: none;
}
<div id="outer">
  Testing 1 2 3
  <div id="inner"></div>
</div>

You need help with javascript

https://codesandbox.io/s/jovial-hodgkin-jqrsp

Disable pointer-events when mouse is down.

发布评论

评论列表(0)

  1. 暂无评论