简体   繁体   English

Internet Explorer 11 和 Edge 中伪元素的 CSS 指针事件

[英]CSS pointer-events for pseudo elements in internet explorer 11 and Edge

So I have a range input with the css rules shown below.所以我有一个范围输入,其 css 规则如下所示。 The goal is to have only the thumb of the range respond to pointer events.目标是让范围的拇指只响应指针事件。 Works fine in Chrome and Safari.在 Chrome 和 Safari 中运行良好。 But in ie-11 and Edge, the entire input stops working.但是在 ie-11 和 Edge 中,整个输入停止工作。 I know that pointer-events is experimental, but I also know it is supported in both of those browsers, but maybe not for pseudo-elements?我知道指针事件是实验性的,但我也知道这两种浏览器都支持它,但可能不适用于伪元素?

input[type="range"] {
    pointer-events: none;
}

input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
}

input[type="range"]::-ms-thumb {
    pointer-events: auto;
}

First, please refer to the following sample:首先,请参考以下示例:

<style>  
    .bottom {
        background: yellow;
        width: 600px;
        height: 200px;
    }
    .top {
        width: 600px;
        height: 200px;
        position: absolute;
        top: 0;
        left: 0;
        /*pointer-events: none;*/
    }
    .test{
        /*pointer-events: none;*/
    }
    div{
            display:block;
    }
</style>

<div>
    <!-- bottom div -->
    <div class="bottom">
        <br>
        <input type="range"/>
        <br>
        <input type="range"  class="test"/>(pointer-events: none)
        <br>
    </div>
    <!-- top div -->
    <div class="top">
    </div>
</div>

In this sample, because the top div is on the top of the range element, so we can't select range (using IE, Microsoft Edge and Microsoft Edge(Chromium)).在这个示例中,由于top div 位于 range 元素的顶部,因此我们无法选择 range(使用 IE、Microsoft Edge 和 Microsoft Edge(Chromium))。

After adding the pointer-events: none;添加pointer-events: none; in the top class, they are able to select.在顶级课程中,他们可以选择。

Then, if we add the pointer-events: none;然后,如果我们添加pointer-events: none; for the second range element, in IE browser and Microsoft Edge (chromium), the second range input can't be selected.对于第二个范围元素,在 IE 浏览器和 Microsoft Edge(铬)中,第二个范围输入无法选择。 But in Microsoft Edge (Microsoft Edge 41.16299.1480.0), it is still can be selected.但是在 Microsoft Edge(Microsoft Edge 41.16299.1480.0)中,它仍然可以选择。 It seems that this is the Edge browser default behavior or issue, I will feedback this issue.看来这是Edge浏览器的默认行为或问题,我会反馈这个问题。 So, you could consider to use this method to add top div.所以,你可以考虑使用这个方法来添加top div。

Second, since the new Microsoft Edge is chromium based, you could try to install the new Microsoft Edge and use it.其次,由于新的 Microsoft Edge是基于铬的,您可以尝试安装新的 Microsoft Edge 并使用它。

Besides, I think there have another choice, you could use JQuery script to find the range input elements and use the disabled property to enable/disable it.此外,我认为还有另一种选择,您可以使用 JQuery 脚本来查找范围输入元素并使用 disabled 属性来启用/禁用它。

    $("input[type='range']")[1].disabled = true; //disable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM