【问题标题】:css transform translateY not working in ie 11 but working with chromecss transform translateY 在 ie 11 中不工作,但在 chrome 中工作
【发布时间】:2018-01-29 10:47:01
【问题描述】:

基本上我正在尝试创建一个放置在右侧的侧面板,当鼠标悬停在 ie11 和 chrome 上时,它会打开,出来时会关闭。所以这是代码在 chrome 中运行良好,但不是在ie11。在 ie11 中,它扩散到视图的下半部分,我希望它覆盖中间的一部分并完美地定位在中间。任何帮助将非常感激。我发现问题出在 css 变换中:translateY 尝试过 -ms-transform -webkit-transform 没有任何效果。 .这里是代码:

<html>
<head><title>Demo</title>
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta charset="utf-8">
</head>

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
    <script
    src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"
    integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
    crossorigin="anonymous"></script>

<body>
    <div id="panel">
        <div id="panel-content">

        </div>
    </div> 
</body>
</html>
<script>



$(function () { 
    //Function to  show side panel on hover
    var $pCont = $("#panel-content");
    $pCont.width(0);
    $('#panel').mouseenter(function(){
        $pCont.stop().animate({width:  27}, 200);
    });
    //Animation for closing the sidepanel when mouseleave 
    $('#panel').mouseleave(function(){
        $("#panel-collapse").hide("slide", { direction: "right" }, 300,function(){
            $pCont.stop().animate({width:  0}, 200);
        });   

    });

});



</script>
<style>

#panel
{
    position: fixed;
    right: 0;
    height:180px;
    width:27px;
    margin-top: 50vh;
    transform: translateY(-50%);  


}

#panel-content
{
    border-radius: 10px 0px 0px 10px;
    position: fixed;
    right: 0;
    background: black;
    height:100%;

}


</style>

【问题讨论】:

  • 你真的把你的&lt;script&gt;&lt;style&gt;放在&lt;html&gt;标签后面了吗?

标签: css google-chrome transform internet-explorer-11


【解决方案1】:

发生这种情况是因为您将 position: fixed 放入 #panel-content 中,所以在 ie11 中页面将成为他的父级,height: 100% 将是页面的高度而不是 #panel 的高度

你不需要使用javascript来做这个悬停,你可以用这个代码来做

here is a fiddle

HTML

<html>
<head><title>Demo</title>
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta charset="utf-8">
</head>

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
    <script
    src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"
    integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
    crossorigin="anonymous"></script>

<body>
    <div id="panel">
        <div id="panel-content">

        </div>
    </div> 
</body>
</html>

CSS

body 
{
 overflow-x: hidden;
}

#panel
{
    position: fixed;
    right: 0;
    height:180px;
    width:27px;
    margin-top: 50vh;
    transform: translateY(-50%);  


}

#panel-content
{
    border-radius: 10px 0px 0px 10px;
    left: 100%;
    position: absolute;
    background: black;
    height:100%;
    width: 100%
    transition: .2s;
}

#panel:hover #panel-content{
    left: 0;
}

【讨论】:

  • 非常感谢您的解释。我会保留 jquery,因为在长版本中,当您将鼠标悬停在面板上时会发生一堆调用。
  • 我明白,我想你会有其他代码使用那个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-07
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 2015-02-12
  • 2018-02-14
  • 1970-01-01
相关资源
最近更新 更多