禁用IE上的悬停功能?

时间:2019-04-07 14:42:51

标签: internet-explorer hover css-transitions

有没有一种方法只能在IE中禁用悬停效果?我知道我可以使用"-ms-transition-property: none !important;"来禁用transition属性,这很好用,但是如果IE中根本没有悬停效果,我希望这样做。之所以要这样做,是因为我在Chrome上有一个"transform: scale(1.05)"元素,它看起来很棒,但是在IE中,transtransios看起来很糟糕,我只是不想因为IE而将其删除。

1 个答案:

答案 0 :(得分:0)

您可以添加一个CSS类并将其transform属性放入其中,然后使用JQuery检查浏览器是否为IE浏览器,然后如果浏览器为IE浏览器,则使用addclass方法添加相关的CSS样式,否则使用removeclass方法,用于从元素中删除CSS样式。

请参考以下示例:

HTML代码:

<body class="gethover">
<div class="box"></div>

CSS代码:

<style>
    .box {
        width: 200px;
        height: 200px;
        margin: 200px auto;
        background-color: cornflowerblue;
        position: relative;
    }

    .gethover .box:hover {
        transform: scale(1.05);
    }

</style>

jQuery代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        if (!!window.ActiveXObject || "ActiveXObject" in window) {
            $('body').removeClass('gethover');
        }
        else {
            $('body').addClass('gethover');
        }
    });
</script>
相关问题