【问题标题】:Css3 animation glitch error Chrome and FirefoxCss3 动画故障错误 Chrome 和 Firefox
【发布时间】:2017-03-13 21:00:48
【问题描述】:

我有这个带有 css 和 bootstrap 的侧边栏菜单: (请缩小 iframe 的大小以查看菜单按钮)

http://jsfiddle.net/s8hts3v7/11/

如果您切换侧边栏菜单,您可以检测到一些故障并且侧边栏在动画中没有平滑。

这种不良影响或故障错误在 Firefox 中更容易检测到。

我用于这个菜单的类是:

/*sidebar nav*/
.navbar-toggle {
    background: #CFD8DC;
    color: #666;
}
.navbar-toggle .icon-bar {
    background: #666;
    width: 17px;
    height: 3px;
}
#sidebar-wrapper {
    background: rgba(0,0,0,.5);
    bottom: 0;
    z-index: 500;
    -webkit-transition-property: background,top,right,bottom,left;
    transition-property: background,top,right,bottom,left;
    -webkit-transition-duration: .5s,0,0,0,0;
    transition-duration: .5s,0,0,0,0;
    -webkit-transition-delay: 0;
    transition-delay: 0;
    -webkit-transition-timing-function: ease;
    transition-timing-function: ease;
}
#sidebar-wrapper.active {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}
#sidebar-menu {
    margin-left: -250px;
    left: 0;
    width: 250px;
    background: #f5f5f5;
    position: fixed;
    height: 100%;
    overflow-y: auto;
    z-index: 1000;
    transition: all 0.5s ease-in 0s;
    -webkit-transition: all 0.5s ease-in 0s;
    -moz-transition: all 0.5s ease-in 0s;
    -ms-transition: all 0.5s ease-in 0s;
    -o-transition: all 0.5s ease-in 0s;
  }

  .sidebar-nav {
    position: absolute;
    top: 0;
    width: 250px;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .sidebar-nav li {
    line-height: 50px;
    text-indent: 20px;
  }

  .sidebar-nav li a {
    color: #999999;
    display: block;
    text-decoration: none;
  }

  .sidebar-nav li a:hover {
    color: #fff;
    background: rgba(255,255,255,0.2);
    text-decoration: none;
  }

  .sidebar-nav li a:active, .sidebar-nav li a:focus {
    text-decoration: none;
  }

  .sidebar-nav > .sidebar-brand {
    height: 55px;
    line-height: 55px;
    font-size: 18px;
    background: white;
    text-indent: initial;
    padding-left: 12px;
  }
  .sidebar-brand img {
    width: 134px;
  }
  .sidebar-brand #menu-close {
    font-size: 26px;
    font-weight: 200;
    display: inline-block;
    vertical-align: middle;
    color: #9E9E9E;
    cursor: pointer;
  }
  .sidebar-nav > .sidebar-brand a {
    color: #999999;
    display: inline-block;
  }

  .sidebar-nav > .sidebar-brand a:hover {
    color: #fff;
    background: none;
  }

  #sidebar-wrapper.active #sidebar-menu {
    left: 250px;
    width: 250px;
    transition: all 0.5s ease-out 0s;
    -webkit-transition: all 0.5s ease-out 0s;
    -moz-transition: all 0.5s ease-out 0s;
    -ms-transition: all 0.5s ease-out 0s;
    -o-transition: all 0.5s ease-out 0s;
  }

  .toggle {
    margin: 5px 5px 0 0;
  }

我该如何解决这个问题?

【问题讨论】:

  • 你真的是说欣赏?

标签: javascript jquery twitter-bootstrap css


【解决方案1】:

#sidebar-wrapper 上评论或删除background: rgba(0,0,0,.5);(切换时覆盖body):

Link to your JSFiddle

火狐:

铬:

$(document).ready(function() {
  $("#menu-close").click(function(e) {
    e.preventDefault();
    $("#sidebar-wrapper").toggleClass("active");
  });
  $("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#sidebar-wrapper").toggleClass("active");
  });
});
html {
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  color: #737373;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  background: #E9E9E9 !important;
}

/*sidebar nav*/

.navbar-toggle {
  background: #CFD8DC !important;
  color: #666 !important;
}

.navbar-toggle .icon-bar {
  background: #666 !important;
  width: 17px !important;
  height: 3px !important;
}

#sidebar-wrapper {
  /* background: rgba(0,0,0,.5); */
  bottom: 0;
  z-index: 500;
  -webkit-transition-property: background, top, right, bottom, left;
  transition-property: background, top, right, bottom, left;
  -webkit-transition-duration: .5s, 0, 0, 0, 0;
  transition-duration: .5s, 0, 0, 0, 0;
  -webkit-transition-delay: 0;
  transition-delay: 0;
  -webkit-transition-timing-function: ease;
  transition-timing-function: ease;
}

#sidebar-wrapper.active {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

#sidebar-menu {
  margin-left: -250px;
  left: 0;
  width: 250px;
  background: #f5f5f5;
  position: fixed;
  height: 100%;
  overflow-y: auto;
  z-index: 1000;
  transition: all 0.5s ease-in 0s;
  -webkit-transition: all 0.5s ease-in 0s;
  -moz-transition: all 0.5s ease-in 0s;
  -ms-transition: all 0.5s ease-in 0s;
  -o-transition: all 0.5s ease-in 0s;
}

.sidebar-nav {
  position: absolute;
  top: 0;
  width: 250px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav li {
  line-height: 50px;
  text-indent: 20px;
}

.sidebar-nav li a {
  color: #999999;
  display: block;
  text-decoration: none;
}

.sidebar-nav li a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  text-decoration: none;
}

.sidebar-nav li a:active,
.sidebar-nav li a:focus {
  text-decoration: none;
}

.sidebar-nav>.sidebar-brand {
  height: 55px;
  line-height: 55px;
  font-size: 18px;
  background: white;
  text-indent: initial;
  padding-left: 12px;
}

.sidebar-brand img {
  width: 134px;
}

.sidebar-brand #menu-close {
  font-size: 26px;
  font-weight: 200;
  display: inline-block;
  vertical-align: middle;
  color: #9E9E9E;
  cursor: pointer;
}

.sidebar-nav>.sidebar-brand a {
  color: #999999;
  display: inline-block;
}

.sidebar-nav>.sidebar-brand a:hover {
  color: #fff;
  background: none;
}

#sidebar-wrapper.active #sidebar-menu {
  left: 250px;
  width: 250px;
  transition: all 0.5s ease-out 0s;
  -webkit-transition: all 0.5s ease-out 0s;
  -moz-transition: all 0.5s ease-out 0s;
  -ms-transition: all 0.5s ease-out 0s;
  -o-transition: all 0.5s ease-out 0s;
}

.toggle {
  margin: 5px 5px 0 0;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body id="fotieditor">
  <div class="container-fluid">
    <button id="menu-toggle" type="button" class="navbar-toggle toggle pull-left" data-toggle="collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
    <div id="sidebar-wrapper">
      <div id="sidebar-menu">
        <ul class="sidebar-nav">
          <li class="sidebar-brand">
            <i id="menu-close" class="fa fa-times-circle-o"></i>
            <a href="#"><img src="https://rp-static.com/www_mantaspersonalizadas/svg/mantas-personalizadas.svg" alt=""></a>
          </li>
          <li>
            <a href="#">Home</a>
          </li>
          <li>
            <a href="#about">About</a>
          </li>
          <li>
            <a href="#contact">Contact</a>
          </li>
        </ul>
      </div>
    </div>

  </div>
</body>

【讨论】:

  • 这没有解决任何问题,只是因为有白色背景,所以看不到故障。
  • 还有我很怀念背景黑色的风格
  • 确实解决了,看上面,我加了一张图。嵌入 sn-p 正在获得背景白色,可能是引导样式表的覆盖。这是在您自己的 sn-p 上在所有浏览器上测试过的,与白色或任何颜色无关。
  • 你能在我的 jsfiddle 中解决它吗?,故障在 Firefox 和 Chrome 中仍然存在
  • 上面加了,解决方法一模一样。
猜你喜欢
  • 2014-11-24
  • 2013-07-28
  • 1970-01-01
  • 2015-10-17
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-12
相关资源
最近更新 更多