【问题标题】:sticky header transition is not smooth粘性标题过渡不平滑
【发布时间】:2017-03-09 18:24:46
【问题描述】:

我创建了一个粘性标题。我也在其中调整徽标图像的大小。 这工作正常。我只是想在徽标图像的大小越来越大时变得平滑。

我能得到任何帮助吗?

https://jsfiddle.net/3v7aen3v/

<script>
    function init() {
      window.addEventListener('scroll', function(e) {
        var distanceY = window.pageYOffset || document.documentElement.scrollTop,
          shrinkOn = 300,
          header = document.querySelector(".header-top");
        if (distanceY > shrinkOn) {
          classie.add(header, "smaller");
        } else {
          if (classie.has(header, "smaller")) {
            classie.remove(header, "smaller");
          }
        }
      });
    }
    window.onload = init();
</script>

<div class="header-top">
  <div class="container clearfix">

    <img src="http://must-munich.com/wp-content/uploads/Logo_MUST-header-subtitle-2-s.png" id="logo" alt="MUST 2016" />

    <nav>
      <a href="">Lorem</a>
      <a href="">Ipsum</a>
      <a href="">Dolor</a>
    </nav>
  </div>
</div>
<!-- /header -->
<div style="height:3000px"></div>

<style>
div.header-top {
  width: 100%;
  height: 150px;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  background-color: #0683c9;
  -webkit-transition: height 0.3s;
  -moz-transition: height 0.3s;
  -ms-transition: height 0.3s;
  -o-transition: height 0.3s;
  transition: height 0.3s;
}

div.header-top img#logo {
  display: inline-block;
  height: 150px;
  /* line-height: 150px;*/
  float: left;
  /* font-family: "Oswald", sans-serif;
    font-size: 60px;
    color: white;*/
  /* font-weight: 400;*/
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -ms-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
}

div.header-top nav {
  display: inline-block;
  float: right;
}

div.header-top nav a {
  line-height: 150px;
  margin-left: 20px;
  color: #9fdbfc;
  font-weight: 700;
  font-size: 18px;
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -ms-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
}

header nav a:hover {
  color: white;
}

div.header-top.smaller {
  height: 100px;
}

div.header-top.smaller img#logo {
  font-size: 30px;
  height: auto;
  line-height: 75px;
  width: 125px;
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -ms-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
}

div.header-top.smaller nav a {
  line-height: 75px;
}
</style>

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:
    div.header-top img#logo {
    display: inline-block;
    height: 150px;
    width:200px;
    float: left;
    font-size: 60px;
    color: white;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    -ms-transition: all 0.3s;
    -o-transition: all 0.3s;
    transition: all 0.3s; }
    

    给你的图片一个宽度,给你的小图片一个高度

     div.header-top.smaller img#logo {
      font-size: 30px;
      height: 100px;
     line-height: 75px;
     width: 125px;
    -webkit-transition: all 0.3s;
     -moz-transition: all 0.3s;
    -ms-transition: all 0.3s;
    -o-transition: all 0.3s;
     transition: all 0.3s; }
    

    https://jsfiddle.net/bc4p26e4/

    【讨论】:

    • 谢谢 XYZ,你能告诉我如何解决这个问题吗?我无法理解修复。
    • 高度:150px;这是您为较大图像和较小 img 高度提供的样式: auto;宽度:125px; .so指定较大图像的宽度,然后它将显示过渡
    • 过渡只能跨数值进行动画处理,因此您必须提供结束和开始过渡的测量值。因此宽度自动或高度自动不起作用。stackoverflow.com/a/7861781/7011496
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    相关资源
    最近更新 更多