文字过渡到重叠

时间:2019-03-07 09:09:21

标签: jquery css

我一直试图将h2元素从h1元素的最终位置放下,使其完全加载并停止其过渡。我无法实现这一目标,目前h2元素只是从h1元素的下方淡入。

这是我的code

$('#header').delay(3250).animate({ 'opacity': [1, "linear"] }, 500);
$('#subheader').delay(4000).animate({ 'opacity': [1, "linear"] }, 500);
h1, h2 {
 opacity: 0;
}

/* HEADER TRANSITION */
.moveHeader {
  -webkit-animation: headerMoving 1.5s;
  animation: headerMoving 1.5s;
  animation-fill-mode: forwards;
  animation-delay: 3s;
}

@-webkit-keyframes headerMoving {
  from {
    -webkit-transform: translateY(-30px);
  }

  to {
    -webkit-transform: translateY(0px);
  }
}

@keyframes headerMoving {
  from {
    transform: translateY(-30px);
  }

  to {
    transform: translateY(0px);
  }
}

/* SUBHEADER TRANSITION */
.moveSub {
  -webkit-animation: subMoving 1s;
  animation: subMoving 1s;
  animation-fill-mode: forwards;
  animation-delay: 4s;
}

@-webkit-keyframes subMoving {
  from {
    -webkit-transform: translateY(-10px);
  }

  to {
    -webkit-transform: translateY(0px);
  }
}

@keyframes subMoving {
  from {
    transform: translateY(-10px);
  }

  to {
    transform: translateY(0px);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1 id="header" class="moveHeader">Header</h1>
<h2 id="subheader" class="moveSub">Subheader</h2>

按run键,动画开始需要3/4秒。

谢谢!

1 个答案:

答案 0 :(得分:3)

像这样?您只需要在子标题转换中将translateY的值从-10更改为-50。试一试,看看最适合您的。

尝试一下,看看是否正是您所需要的。

$('#header').delay(3250).animate({ 'opacity': [1, "linear"] }, 500);
$('#subheader').delay(4000).animate({ 'opacity': [1, "linear"] }, 500);
h1, h2 {
 opacity: 0;
}

/* HEADER TRANSITION */
.moveHeader {
  -webkit-animation: headerMoving 1.5s;
  animation: headerMoving 1.5s;
  animation-fill-mode: forwards;
  animation-delay: 3s;
}

@-webkit-keyframes headerMoving {
  from {
    -webkit-transform: translateY(-30px);
  }

  to {
    -webkit-transform: translateY(0px);
  }
}

@keyframes headerMoving {
  from {
    transform: translateY(-30px);
  }

  to {
    transform: translateY(0px);
  }
}

/* SUBHEADER TRANSITION */
.moveSub {
  -webkit-animation: subMoving 1s;
  animation: subMoving 1s;
  animation-fill-mode: forwards;
  animation-delay: 4s;
}

@-webkit-keyframes subMoving {
  from {
    -webkit-transform: translateY(-50px);
  }

  to {
    -webkit-transform: translateY(0px);
  }
}

@keyframes subMoving {
  from {
    transform: translateY(-50px);
  }

  to {
    transform: translateY(0px);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1 id="header" class="moveHeader">Header</h1>
<h2 id="subheader" class="moveSub">Subheader</h2>