Jump to content
GreenSock

jstafford

Page Transform timeline not reversing when menu open

Moderator Tag

Recommended Posts

Hi, so here is the idea for what I want to do.

 

- Click on the blue square in upper right and the page transform occurs revealing menu underneath.

 

- Click on the red square when the menu is open, and another page transform occurs closing the menu and revealing page again

 

I am having difficulty understanding what is going on here. I am only using one timeline and when I click on the red square the timeline stalls out . Not sure why?

 

Here is an example of the open and close effect occuring automatically without the click triggering the event.

 

See the Pen zrzEoj by jstafford (@jstafford) on CodePen

See the Pen wMpEpr by jstafford (@jstafford) on CodePen

Link to comment
Share on other sites

from what I can tell, you shouldn't be building your timeline inside menuRevealHideAnimation(). Notice you call that function twice

menuRevealHideAnimation($("#closeMenuContainer"));
menuRevealHideAnimation($("#openMenuContainer"));

which creates two timelines on the same element.

 

try this:

http://codepen.io/GreenSock/pen/mVpGam?editors=001

  • Like 3
Link to comment
Share on other sites

Admittedly, I am not a JQuery or JavaScript expert, but would like to become one eventually. Why is it that when I break up this solution into index.html, script.js, style.css files it stops working. Feeling very helpless right now.

 

 
//index.html
<!DOCTYPE html>
<html>
<head>
    <!-- dependencies -->
<script src="dependencies/jquery-2.1.4.min.js"></script>
<script src="dependencies/jquery.gsap.min.js"></script>
<script src="dependencies/TweenMax.min.js"></script>
<script src="dependencies/DrawSVGPlugin.min.js"></script>
 
<script src="script.js"></script>
<link href="style.css" rel="stylesheet"/>
</head>
 
<body><!-- load imgs via ajax with src below -->
 
<div id="mainMenu" class="menu">
<div id="closeMenuContainer">
<div id="closeMenu">
 
</div>
</div>
 
<div class="navLinkContainer"><a id="mainCategoryHome" class="navLink"></a></div>
<div class="navLinkContainer"><a id="mainCategoryInsuranceProducts" class="navLink"></a></div>
<div class="navLinkContainer"><a id="mainCategoryFinancialProducts" class="navLink"></a></div>
<div class="navLinkContainer"><a id="mainCategoryClaims" class="navLink"></a></div>
<div class="navLinkContainer"><a id="mainCategoryContact" class="navLink"></a></div>
</div>
 
<div class="site">
  <div class="pageContentContainer">
    <div id="homePageContent" class="pageContent">
<div id="openMenuContainer">
<div id="openMenu">
 
</div>
</div>
      <p><strong>GSAP</strong> Page Transform<br></p>
    </div>
  </div>
</div>
<script>
$(document).ready(function() {  
$(window).load(function() {
 
init();
 
function init() {
initMenuRevealAnimation();
}
});
});
</script>
</body>
</html>
 
//script.js
initMenuRevealAnimation();
 
function initMenuRevealAnimation() {
menuRevealHideAnimation($("#closeMenuContainer"));
menuRevealHideAnimation($("#openMenuContainer"));
}
 
 
var tl = new TimelineMax({paused:true});
tl.set('.pageContentContainer', { perspective: "1200px" });
tl.set('#homePageContent', { transformOrigin: "100% 50%"});
tl.set(".site", {pointerEvents: "auto"});
tl.to('.pageContent', 0.5, {opacity: 0.5, scale: 0.7,  rotationY: -60, ease: Back.easeInOut },0)
 .to('.pageContent', 0.25, {scale: 1}, 0.5)
 .to(".site", 0.01, {pointerEvents:"none"}, 0.5);
 
 
function menuRevealHideAnimation(el) {
 
 
$(el).on("click", function() {
if(!$("#mainMenu").hasClass("open")) {
openMenu();
$("#mainMenu").addClass("open");
} else {
closeMenu();
$("#mainMenu").removeClass("open");
}
})
 
function openMenu() {
tl.play();
}
 
function closeMenu() {
tl.reverse();
}
}
 
//style.css
#closeMenuContainer {
width: 50px;
height: 50px;
z-index: 0;
left: 24%;
top: 1.5%;
border: 1px solid red;
}
 
#openMenuContainer {
position: absolute;
width: 50px;
height: 50px;
right: 1%;
top: 1.5%;
border: 1px solid blue;
}
 
.menu {
    position: absolute;
    z-index: 0;
width: 35%;
    height:auto; 
}
 
html, body {
   height: 100%;
  background: #B8B6B4;
  -webkit-font-smoothing: antialiased;
}
 
.site {
margin: -7px -7px;
    height: 100%;
    overflow: hidden;
}
 
.pageContentContainer {
  position: relative;
    z-index: 2;
 
  width: 100%;
  height: 100%;
  overflow: hidden;
}
 
.pageContent {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  z-index: 0;
  width: 100%;
  height: 100%;
  background: #e74c3c;
  box-shadow: 20px 20px 15px 0px #939290;
}
 
.pageContent p {
  position: absolute;
  top: 50%;
  width: 100%;
  text-align: center;
  font-family: Montserrat, sans-serif;
  font-size: 75px;
  text-transform: uppercase;
  color: #fff;
  font-weight: 400;
  margin: 0;
  line-height: 1;
}
 
.pageContentt p strong {
  font-weight: 700;
}
 
.pageContent p em {
  font-family: 'Playfair Display', serif;
  text-transform: none;
  font-style: italic;
  font-weight: normal;
  font-size: 25px;
  margin-top: 7px;
  display: block;
}
Link to comment
Share on other sites

variable scope problem? something that is recognized while in codpen but not in in local?

Link to comment
Share on other sites

First step is to open the javascript console and look for errors: https://developer.chrome.com/devtools/docs/console

 

It could be a single mis-typed character. Unfortunately, it would be pretty time consuming to analyze all that code you pasted. Much better to provide a URL for us to see.

 

My recommendation is to start with something that works and build backwards slowly.

In case you haven't already, start by exporting a zip of the working codepen demo and then add dependencies and move things around as needed. test after each step.  To export a zip of a pen hit the "export" button in the lower right corner: http://prntscr.com/9t1akn

  • Like 1
Link to comment
Share on other sites

it was fixed when I put the external javascript into my window.load in the index.html. Now this is not necessarily where I want to keep it, but I am trying to understand my the script.js wasn't fully processed by the time it got inside the following:

 

$(window).load(function() {
 
        init();
 
        function init() {
             initMenuRevealAnimation();
        }
});
Link to comment
Share on other sites

I understand Carl. I tried to make this initial codepen as reduced as possible because I know you guys deal with a lot of analysis of other people's code. Not one of my forte's. I moved the external script to the end of the DOM and it worked fine.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×