Smooth Page Section Transition Effect with jQuery

File Size: 2.21 KB
Views Total: 4606
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Smooth Page Section Transition Effect with jQuery

Just another page transition effect which allows you to switch between content sections with a subtle transition effect based on jQuery animate() method.

Basic usage:

1. Create two content sections you want to switch between.

<section class="section-one">
  <div class="container">
    This is Section One
    <button class="transition-button-one">
      Go To Section Two
    </button>
  </div>
</section>

<section class="section-two">
  <div class="container">
    This is Section Two
    <button class="transition-button-two">
      Go To Section One
    </button>
  </div>
</section>

2. Style the content sections and make them full height.

section {
  padding: 30px 0;
  margin: 0;
  position: absolute;
  overflow: hidden;
  height: 100vh;
  top: 0;
  left: 0;
}

section.section-one {
  background: #4089A6;
  height: 100vh;
  z-index: 99;
  border-top: 1px solid #4089A6;
  border-bottom: 1px solid #4089A6;
}

section.section-two {
  background: #3bb17c;
  height: 2px;
  padding: 0;
  top: 50vh;
  left: 50%;
  width: 5px;
  display: none;
  border-top: 1px solid #3bb17c;
  border-bottom: 1px solid #3bb17c;
}

3. Include the latest version of jQuery JavaScript library from a CDN.

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script> 

4. The JavaScript to active the section transition effect.

$(function () {


"use strict";

var section1  = $(".section-one"),
    section2 = $(".section-two");

$(".transition-button-one").click(function () {

    section1.animate({
        'height': '0',
        'top': '50vh',
        'padding': '0'
    }, 300)
    .animate({
        'width': '2px',
        'left': '50%'
    }, 900)
    .fadeOut(200, function () {
        section2.fadeIn(200);
        section2.animate({
            'width': '100%',
            'left': '0'
        }, 900);
        section2.animate({
            'min-height': '100vh',
            'top': '0',
            'padding-top': '50px',
            'padding-bottom': '50px'
        }, 300);
    });


});

$(".transition-button-two").click(function () {

    section2.animate({
        'min-height': '0',
        'height': '0',
        'top': '50vh',
        'padding': '0'
    }, 300)
    .animate({
        'width': '2px',
        'left': '50%'
    }, 900)
    .fadeOut(200, function () {
        section1.fadeIn(200)
        .animate({
            'width': '100%',
            'left': '0'
        }, 900)
        .animate({
            'height': '100vh',
            'top': '0',
            'padding-top': '100px',
            'padding-bottom': '100px'
        }, 300);
    });
});
});

This awesome jQuery plugin is developed by Mhmdhasan. For more Advanced Usages, please check the demo page or visit the official website.