html - 在CSS中从上到下过渡图像

标签 html css

我想从上到下方向传输我的图像。现在是从左下到上过渡。

HTML

<header>
<img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png"><br/>
<img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png"><br/>
<img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png"></header>

JS

$(window).scroll(function() {
if ($(this).scrollTop() > 1){  
    $('header').addClass("sticky");
  }
  else{
    $('header').removeClass("sticky");
  }
});

CSS

header{
  position: fixed;
  width: 100%;
  text-align: center;
  font-size: 72px;
  line-height: 108px;
  color: #fff;
  font-family: 'PT Sans', sans-serif;
  opacity : 0;
}

header.sticky {
  font-size: 24px;
  line-height: 48px;
  text-align: left;
  padding-left: 20px;
  transition: all 0.6s ease;
  opacity : 1;
  animation-direction: normal;
}

body{
  height:1000px
}

代码笔:http://codepen.io/anon/pen/ezNZQV

最佳答案

添加 padding-left: 20px;header 就像在 header.sticky 上一样。要从上到下设置动画,请将 bottom:0; 添加到 header

代码(https://jsfiddle.net/6kbcp54m/1/):

$(window).scroll(function() {
  if ($(this).scrollTop() > 1){  
    $('header').addClass("sticky");
  }
  else{
    $('header').removeClass("sticky");
  }
});
header {
  position: fixed;
  width: 100%;
  text-align: center;
  font-size: 72px;
  line-height: 108px;
  color: #fff;
  font-family: 'PT Sans', sans-serif;
  opacity : 0;
  padding-left: 20px;
  bottom:0;
}
header.sticky {
  font-size: 24px;
  line-height: 48px;
  text-align: left;
  padding-left: 20px;
  transition: all 0.6s ease;
  opacity : 1;
  animation-direction: normal;
}
body {
  height:1000px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
  <img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png"><br/>
  <img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png"><br/>
  <img src="http://res.cloudinary.com/paresh/image/upload/v1464936481/imgpsh_fullsize_aab4vm.png">
</header>

关于html - 在CSS中从上到下过渡图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37607888/

相关文章:

html - Bootstrap header 不是不透明的

css - HTML 颜色选择器输入

html - 如何水平对齐两个大小不同的div

css - 为什么 Mudblazor 组件在没有 css 的情况下出现?

html - CSS - 位置固定改变元素的宽度

html - 在 wordpress 中阅读更多链接

html - 如何在 Joomla 中添加搜索模块作为菜单项?

javascript - 如何在javascript中的图像上添加可拖动的文本

css - colab 不使用 css

jquery - 如何定位一个类的子类(特别是添加和删除这个类)