IE10浏览器,父元素中的有图片定位后,其余子元素定位点击事件失效

今天分享一下关于IE10的bug:

项目需求兼容IE10,但是在兼容过程中发现一个神奇的事情,就是当一个父元素中有图片,有其他元素时,先把img定位,z-index设置为16,div设置为20,这时候,正常来讲,,点击div应该有正常事件的触发,但是IE10中却无效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="father">
        <img class="img" src="https://pics0.baidu.com/feed/c83d70cf3bc79f3d5ebcc171e6486217738b2905.jpeg?token=3ebd379de5631597ff08f81a7aa1ef97&s=F73A5CCBCE686815530D89120300C053" alt="">
        <div class="left">

        </div>
        <div class="right">

        </div>
    </div>
</body>
</html>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
    $('.left').click(function() {
        alert('left click')
    })
    $('.right').click(function() {
        alert('right click')
    })
</script>
<style>
    .father {
        position: relative;
        width: 400px;
        height: 200px;
        background: #434343;
    }
    .img {
        width: 400px;
        height: 200px;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 16;
    }
    .left {
        width: 100px;
        height: 100px;;
        position: absolute;
        left: 0px;
        top: 0px;
        z-index: 20;
    }
    .right {
        width: 100px;
        height: 100px;
        position: absolute;
        top: 0px;
        right: 0px;
        z-index: 20;
    }
</style>

此时在Google中点击,两个子元素的点击事件均可以正常触发

 

在IE10浏览器中,点击事件均无效果,通过一些列观察,发现,元素根本找不到。。

 

 

元素都没有,所以点击事件妥妥的是无效的~~~

通过查阅资料发现,大佬们提供的思路,发现只要给diiv设置的背景色,神奇的一幕就发生了!

    .left {
        width: 100px;
        height: 100px;;
        position: absolute;
        left: 0px;
        top: 0px;
        z-index: 20;
        background: #903;
    }
    .right {
        width: 100px;
        height: 100px;
        position: absolute;
        top: 0px;
        right: 0px;
        z-index: 20;
        background: #777;
    }

 

正常了!!!!终于正常了!!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值