Jquery 页面动画转换

Jquery 页面动画转换,jquery,html,css,Jquery,Html,Css,我正在尝试使用@Keyframe CSS3创建一个漂亮的过渡,如果可能的话,还可以使用jQuery来处理按钮的请求 基本上,这个概念是当点击“开始动画”按钮时,它必须将页面从第1页动画到第2页,与此视频完全相似: 这是我的HTML: <main> <div class="cd-index cd-main-content"> <div> <h1>Animated Page Transition<

我正在尝试使用@Keyframe CSS3创建一个漂亮的过渡,如果可能的话,还可以使用jQuery来处理按钮的请求

基本上,这个概念是当点击“开始动画”按钮时,它必须将页面从第1页动画到第2页,与此视频完全相似:

这是我的HTML:

<main>
    <div class="cd-index cd-main-content">
        <div>
            <h1>Animated Page Transition</h1>

            <a class="cd-btn" href="about.html" data-type="page-transition">Start animation</a>
        </div>
    </div>
</main>
如果您可以帮助使用JSFIDLE来创建这种效果,并看看如何调整代码,那将非常棒。这对我来说真的很难。希望任何人都能在JSFIDLE中帮助我:


到目前为止,我得到的是:

不幸的是,您的JSFIDLE在我的浏览器中似乎不起作用,这使得我很难给出确切的答案。 不过我确实看了视频,并编写了一些代码作为示例

a{
显示:块;
位置:绝对位置;
左:50%;
最高:50%;
转换:翻译(-50%,-50%);
宽度:300px;
高度:300px;
背景色:#0ff;
过渡:宽度5s放松1s,高度5s放松1s,变换1s放松0s;
}
a:焦点{
宽度:20px;
高度:100px;
变换:平移(-50%,-50%)旋转(90度);
转换延迟:0s、0s、5s;
}

不幸的是,您的JSFIDLE在我的浏览器中似乎不起作用,这使得我很难给出确切的答案。 不过我确实看了视频,并编写了一些代码作为示例

a{
显示:块;
位置:绝对位置;
左:50%;
最高:50%;
转换:翻译(-50%,-50%);
宽度:300px;
高度:300px;
背景色:#0ff;
过渡:宽度5s放松1s,高度5s放松1s,变换1s放松0s;
}
a:焦点{
宽度:20px;
高度:100px;
变换:平移(-50%,-50%)旋转(90度);
转换延迟:0s、0s、5s;
}
Primary style

-------------------------------- */
*, *::after, *::before {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

body {
  font-size: 1.6rem;
  font-family: "Open Sans", sans-serif;
  color: #4089a6;
  background-color: #ffffff;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: #283040;
  text-decoration: none;
}

h1 {
  color: #ffffff;
  margin-bottom: 1em;
  font-size: 2.2rem;
}
@media only screen and (min-width: 768px) {
  h1 {
    font-size: 4.4rem;
    font-weight: 300;
  }
}

/* -------------------------------- 

Patterns - reusable parts of our design

-------------------------------- */
.cd-btn {
  display: inline-block;
  padding: 1.4em 1.6em;
  margin-bottom: 2em;
  border-radius: 50em;
  background-color: #283040;
  color: #ffffff;
  font-weight: bold;
  font-size: 1.3rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}
.no-touch .cd-btn:hover {
  background-color: #323c50;
}
.cd-about .cd-btn {
  background-color: #4089a6;
}

/* -------------------------------- 

Main Components 

-------------------------------- */
body::after, body::before {
  /* these are the 2 half blocks which cover the content once the animation is triggered */
  content: '';
  height: 50vh;
  width: 100%;
  position: fixed;
  left: 0;
  background-color: #ffffff;
  z-index: 1;
  /* Force Hardware Acceleration */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-transition: -webkit-transform 0.4s 0.4s;
  -moz-transition: -moz-transform 0.4s 0.4s;
  transition: transform 0.4s 0.4s;
}
body::before {
  top: 0;
  -webkit-transform: translateY(-100%);
  -moz-transform: translateY(-100%);
  -ms-transform: translateY(-100%);
  -o-transform: translateY(-100%);
  transform: translateY(-100%);
}
body::after {
  bottom: 0;
  -webkit-transform: translateY(100%);
  -moz-transform: translateY(100%);
  -ms-transform: translateY(100%);
  -o-transform: translateY(100%);
  transform: translateY(100%);
}
body.page-is-changing::after, body.page-is-changing::before {
  -webkit-transform: translateY(0);
  -moz-transform: translateY(0);
  -ms-transform: translateY(0);
  -o-transform: translateY(0);
  transform: translateY(0);
  -webkit-transition: -webkit-transform 0.4s 0s;
  -moz-transition: -moz-transform 0.4s 0s;
  transition: transform 0.4s 0s;
}

main {
  height: 100vh;
  padding: 10px;
  text-align: center;
}
main .cd-main-content {
  position: relative;
  height: calc(100vh - 20px);
}
main .cd-main-content > div {
  height: 100%;
  overflow: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
main .cd-main-content::after, main .cd-main-content::before {
  /* these are the 2 gradient overlay at the top and bottom of the .cd-main-content - to indicate that you can scroll */
  content: '';
  position: absolute;
  left: 0;
  height: 50px;
  width: 100%;
}
main .cd-main-content::before {
  top: 0;
}
main .cd-main-content::after {
  bottom: 0;
}
main .cd-main-content.cd-index {
  /* .cd-main-content basic style - index page */
  background-color: #4089a6;
  /* vertically center its content */
  display: table;
  width: 100%;
}
main .cd-main-content.cd-index > div {
  /* vertically center the content inside the .cd-index */
  display: table-cell;
  vertical-align: middle;
}
main .cd-main-content.cd-index::after {
  background-color: rgba(64, 137, 166, 0);
  background-image: -webkit-linear-gradient(bottom, #4089a6, rgba(64, 137, 166, 0));
  background-image: linear-gradient(to top,#4089a6, rgba(64, 137, 166, 0));
}
main .cd-main-content.cd-index::before {
  background-color: rgba(64, 137, 166, 0);
  background-image: -webkit-linear-gradient(top, #4089a6, rgba(64, 137, 166, 0));
  background-image: linear-gradient(to bottom,#4089a6, rgba(64, 137, 166, 0));
}
main .cd-main-content.cd-about {
  /* .cd-main-content basic style - about page */
  background-color: #283040;
}
main .cd-main-content.cd-about > div {
  padding-top: 50px;
}
main .cd-main-content.cd-about::after {
  background-color: rgba(40, 48, 64, 0);
  background-image: -webkit-linear-gradient(bottom, #283040, rgba(40, 48, 64, 0));
  background-image: linear-gradient(to top,#283040, rgba(40, 48, 64, 0));
}
main .cd-main-content.cd-about::before {
  background-color: rgba(40, 48, 64, 0);
  background-image: -webkit-linear-gradient(top, #283040, rgba(40, 48, 64, 0));
  background-image: linear-gradient(to bottom,#283040, rgba(40, 48, 64, 0));
}
main p {
  width: 90%;
  max-width: 768px;
  margin: 3em auto;
  font-size: 1.4rem;
  line-height: 1.6;
  color: #535966;
  text-align: left;
}
@media only screen and (min-width: 768px) {
  main {
    padding: 20px;
  }
  main .cd-main-content {
    height: calc(100vh - 40px);
  }
  main.cd-index > div {
    padding-top: 200px;
  }
  main.cd-index > div {
    padding-top: 50px;
  }
  main p {
    font-size: 1.8rem;
    line-height: 2;
  }
}

.cd-cover-layer {
  /* layer that covers the content when the animation is triggered */
  position: fixed;
  left: 50%;
  top: 50%;
  bottom: auto;
  right: auto;
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  -o-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
  height: calc(100% - 20px);
  width: calc(100% - 20px);
  opacity: 0;
  visibility: hidden;
  background-color: #4089a6;
  -webkit-transition: opacity 0.4s 0.4s, visibility 0s 0.8s;
  -moz-transition: opacity 0.4s 0.4s, visibility 0s 0.8s;
  transition: opacity 0.4s 0.4s, visibility 0s 0.8s;
}
.cd-about .cd-cover-layer {
  background-color: #283040;
}
.page-is-changing .cd-cover-layer {
  opacity: 1;
  visibility: visible;
  -webkit-transition: opacity 0.3s 0s, visibility 0s 0s;
  -moz-transition: opacity 0.3s 0s, visibility 0s 0s;
  transition: opacity 0.3s 0s, visibility 0s 0s;
}
@media only screen and (min-width: 768px) {
  .cd-cover-layer {
    height: calc(100% - 40px);
    width: calc(100% - 40px);
  }
}

.cd-loading-bar {
  /* this is the loding bar - visible while switching from one page to the following one */
  position: fixed;
  z-index: 2;
  left: 50%;
  top: 50%;
  height: 2px;
  width: 90%;
  background-color: #4089a6;
  visibility: hidden;
  -webkit-transition: visibility 0s 0.4s, -webkit-transform 0.4s 0s ease-in;
  -moz-transition: visibility 0s 0.4s, -moz-transform 0.4s 0s ease-in;
  transition: visibility 0s 0.4s, transform 0.4s 0s ease-in;
  /* Force Hardware Acceleration */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  -o-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}
.cd-about .cd-loading-bar {
  background-color: #283040;
}
.cd-about .cd-loading-bar::before {
  background-color: #4089a6;
}
.cd-loading-bar::before {
  /* this is the progress bar inside the loading bar */
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  background-color: #283040;
  /* Force Hardware Acceleration */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-transform: scaleX(0);
  -moz-transform: scaleX(0);
  -ms-transform: scaleX(0);
  -o-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transform-origin: left center;
  -moz-transform-origin: left center;
  -ms-transform-origin: left center;
  -o-transform-origin: left center;
  transform-origin: left center;
}
.page-is-changing .cd-loading-bar {
  visibility: visible;
  -webkit-transform: translateX(-50%) translateY(-50%) scaleX(0.3);
  -moz-transform: translateX(-50%) translateY(-50%) scaleX(0.3);
  -ms-transform: translateX(-50%) translateY(-50%) scaleX(0.3);
  -o-transform: translateX(-50%) translateY(-50%) scaleX(0.3);
  transform: translateX(-50%) translateY(-50%) scaleX(0.3);
  -webkit-transition: visibility 0s 0.3s, -webkit-transform 0.4s 0.4s;
  -moz-transition: visibility 0s 0.3s, -moz-transform 0.4s 0.4s;
  transition: visibility 0s 0.3s, transform 0.4s 0.4s;
}
.page-is-changing .cd-loading-bar::before {
  -webkit-transform: scaleX(1);
  -moz-transform: scaleX(1);
  -ms-transform: scaleX(1);
  -o-transform: scaleX(1);
  transform: scaleX(1);
  -webkit-transition: -webkit-transform 0.8s 0.8s ease-in;
  -moz-transition: -moz-transform 0.8s 0.8s ease-in;
  transition: transform 0.8s 0.8s ease-in;
}
@media only screen and (min-width: 768px) {
  .cd-loading-bar {
    width: calc(100% - 40px);
  }
}