css - 悬停在 IE11 和 Edge 上不起作用

标签 css hover internet-explorer-11 microsoft-edge

我试图通过使用媒体查询在鼠标指针位于 iframe 上时扩展和收缩 iframe。

但是,它不起作用,但是,当鼠标点在框架边框上时,它会展开和收缩。

有人知道如何在 IE11 和 Edge 上解决这个问题吗?

此外,由于同源策略,我不能在 iframe 之外使用 jQuery。因此,我可能必须修复 css 才能实现此动画。

<html>
  <head>
  <style type="text/css">
  iframe[id^=sidebanner]{
    width: 80px;
  }
  iframe#sidebanner{
    right: 0;
  }
  iframe[id^=sidebanner]:hover{
    width: auto;
    -webkit-transition: width ease-in-out 0.1s;
    -moz-transition: width ease-in-out 0.1s;
    -ms-transition: width ease-in-out 0.1s;
    -o-transition: width ease-in-out 0.1s;
    transition: width ease-in-out 0.1s;

  }
  @media all and (max-width: 2500px) {
    iframe[id^=sidebanner]:hover{
      width: 50%;
    }

  }
  @media all and (max-width: 900px) {
    iframe[id^=sidebanner]:hover{
      width: 55%;
    }
  }
  @media all and (max-width: 800px) {
    iframe[id^=sidebanner]:hover{
      width: 60%;
    }
  }
  @media all and (max-width: 750px) {
    iframe[id^=sidebanner]:hover{
      width: 65%;
    }
  }
  @media all and (max-width: 700px) {
    iframe[id^=sidebanner]:hover{
      width: 70%;
    }
  }
  @media all and (max-width: 650px) {
    iframe[id^=sidebanner]:hover{
      width: 75%;
    }
  }
  @media all and (max-width: 600px) {
    iframe[id^=sidebanner]:hover{
      width: 80%;
    }
  }
  </style>

  </head>
  <body>

  <iframe id="sidebanner" src="" frameborder="1" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="true" style="top: 0px; height: 100%; right: 0px;"></iframe>

  </body>
  </html>

最佳答案

我发现您可以使用 jquery 添加一个 hover 类,它将包含扩展 iframe 所需的 css。

$('#sidebanner').hover(
       function(){ $(this).addClass('hover') },
       function(){ $(this).removeClass('hover') }
)

使用这个函数,我们只需告诉我们添加一个类 hover 到我们的 #sidebanner id

您还需要将 css 添加到 hover 类。这将与 iframe[id^=sidebanner]:hover 中使用的 css 相同。还将 hover 类添加到您的 @media 查询中。

.hover {
    -webkit-transition: width ease-in-out 0.1s;
    -moz-transition: width ease-in-out 0.1s;
    -ms-transition: width ease-in-out 0.1s;
    -o-transition: width ease-in-out 0.1s;
    transition: width ease-in-out 0.1s;
  }

示例:https://jsfiddle.net/c9syw731/2/

关于css - 悬停在 IE11 和 Edge 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46232707/

相关文章:

html - CSS 文本的宽度过渡不起作用

CSS3 动画在 IE11 中不工作,但在其他浏览器中工作

css - 链接悬停关闭不透明度

javascript - Div 在悬停时闪烁

html - 不能宽度 :100% and text-align:center

css - 我怎样才能使我的边界半径曲线向外?

javascript - 如何防止IE11弹窗(您确定要离开此页面吗)

css - 在 IE 11 中使用最大宽度和最大高度保持图像比例

html - 100% 高度转换

html - CSS 中的居中 block