【问题标题】:Disable hover on IE?禁用 IE 上的悬停?
【发布时间】:2019-08-28 19:40:09
【问题描述】:

有没有办法只在 IE 中禁用悬停效果?我知道我可以使用"-ms-transition-property: none !important;" 禁用转换属性,并且工作正常,但如果 IE 中根本没有悬停效果,我会喜欢它。我想这样做的原因是因为我在 Chrome 上有一个带有"transform: scale(1.05)" 的元素,它看起来很棒,但是在 IE 中transitionios 看起来很糟糕,我只是不想因为 IE 而到处删除它。

【问题讨论】:

  • 您的页面是如何设计的?您能否分享相关代码,以便我可以重现您的问题并找到解决方案。

标签: internet-explorer hover css-transitions


【解决方案1】:

你可以添加一个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>

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 2017-08-11
    • 2013-01-16
    • 2011-06-07
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多