What might be causing the sudden shifts in element positions during TweenLite animation?

I have created a demo of my code in this JSFiddle and also included it below. The issue I am facing occurs in Google Chrome, so I would recommend using that browser to replicate and fix the bug. Please note that the code is a snippet from a larger project and may not be perfectly simplified.

My web app uses JQuery and GreenSock's TweenLite for animations. The app consists of menus that can be transitioned using the bodyChange() function. This function takes two parameters:

  • nextOrPrev: Determines whether to run the next or previous animation based on the value provided ("next" or "prev"). Currently, only the "next" animation is functional.
  • bodyFunction: Specifies the function that fills the body with menu elements and wraps them in #bodyWrap.

In the demo, there are two menus: mainMenu with a #playButton. Clicking the button triggers the bodyChange() function with the parameters ("next", playSettingsBody), which switches to the playSettings menu.

The issue arises when clicking the playButton. Instead of staying in place and executing the animation, the button jumps up on the screen. I am unsure of the reason behind this behavior and would appreciate any assistance in identifying the mistake.

Thank you for your help.


mainMenuBody();

function mainMenuBody() {
$("body").append(
"<div id='playButton' class='mainButton'><div class='buttonText mainButtonText text'>PLAY</div></div>"
);

$("body").wrapInner("<div id='bodyWrap'></div>");

$("#playButton").bind("click", function() {
bodyChange("next", playSettingsBody);
});
}

function bodyChange(nextOrPrev, bodyFunction) {
switch (nextOrPrev) {
case "next":
TweenLite.to($("#bodyWrap"), .4, {
ease: Power2.easeIn,
transform: "rotateY(90deg)",
onComplete: function(){
$("body").empty();
bodyFunction();
TweenLite.from($("#bodyWrap"), .4, {
ease: Power2.easeOut,
transform: "rotateY(90deg)"
});
}
});
break;

case "prev":
alert("prev");
}
}

function playSettingsBody() {
$("body").append(
"<p class='text' id='CYTText'>This is the second menu!</p>"
);
}

Answer №1

The issue lies within the .mainButton class in your code snippet.

.mainButton {
    position: absolute;
    top: 150px;
    bottom: 0;
    //rest
}

Removing the line bottom: 0; resolves the problem in your JSFiddle. However, if you remove top: 150px; but keep bottom: 0, the issue persists. Unfortunately, I am unable to provide an explanation for this behavior. Consider seeking assistance on the GSAP forums to understand why bottom works differently from top in this context.

Edit
Since you require bottom: 0 and I couldn't resolve the issue in your code, I have created a sample using Timeline, a GSAP plugin. You can view this on JSFiddle or see the code snippet below.

var tl = new TimelineMax();
tl.pause();
tl.fromTo($("#click"), 1, {rotationY: 0, ease: Power2.easeOut}, {rotationY: 90, transformOrigin:"right", ease: Power2.easeOut})
  .set($("#click2"), {css:{display: "table"}}, "-=0.6")
  .fromTo($("#click2"), 1, {rotationY: -90, ease: Power2.easeOut}, {rotationY: 0, transformOrigin:"left", ease: Power2.easeOut}, "-=0.6");

$("#click").click(function() {
  tl.play();
});

$("#click2").click(function() {
  tl.reverse();
});
* {
  margin: 0;
  padding: 0;
}

body {
  background-image: url("../resources/pics/Vignette2.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  background-color: #02BFC1;
  overflow: hidden;
}

div.one, div.two {
  position: absolute;
  bottom: 0;
  height: 200px;
  width: 200px;
  background: #F37C2B;
  text-align: center;
  display: table;
  cursor: pointer;
  border: 10px solid #F1F2F0;
}
div.one .text, div.two .text {
  position: relative;
  display: table-cell;
  vertical-align: middle;
  color: #FFFFFF;
  font-family: Bebas Neue;
  font-size: 90px;
}
div.two {
  display: none;
  border-color: transparent;
  background: none;
}
div.two .text {
  font-size: 40px;
}
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js"></script>

<div id="click" class="one">
  <div class="text">
    Play
  </div>
</div>

<div id="click2" class="two">
  <div class="text">
    Second Menu
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update the page when the React route changes

I am facing an issue with a function in a component that is supposed to load certain variables when the page is fully loaded. Interestingly, it works perfectly fine when manually reloading the page. However, if I use a NavLink to navigate to the page, the ...

Error encountered with Three.js SceneExporter due to Uncaught Syntax issue

Recently, I've been attempting to export a three.js scene using the SceneExporter tool. Here is the code snippet I have been working with: var output = new THREE.SceneExporter().parse(scope.renderingEngine.scene); Unfortunately, this has resulted in ...

What is the method for a Greasemonkey script to divide a link into three interconnected links?

My goal is to use Greasemonkey to link Redmine issue numbers found in cgit commit messages to their respective issues or projects. The cgit commit message HTML source looks like this: <a href='/editingmodule/commit/?id=49e4a33e0f8b306ded5'&g ...

Chrome fails to load webfont upon page initialization

Encountering a problem with loading a WebFont specifically on Chrome version "48.0.2564.82 m (64-bit)". The issue arises from the webfont not being applied upon page load or navigation, unless I manually refresh the page. Below is the snippet of code fro ...

Submitting a Laravel form seamlessly without triggering a page refresh

In my Laravel 5.7 Project, I have a dilemma that needs resolving: Within my system, there is a table displaying all users with a column labeled Status, indicating whether they are Active or Inactive... Currently, in my Blade template, there is a select o ...

Show the image on top of the div block as the AJAX content loads

Implementing this task may seem easy and common, but I am struggling to figure it out! What should take five minutes has turned into an hour of frustration. Please lend me your expertise in getting this done. I have a div container block: <div cla ...

Utilize puppeteer by passing a function inside page.waitForFunction() for efficient automation processes

Below is the code I am using: function checkDataRefresh(pastAvgGain, currentAvgGain) { if (pastAvgGain !== currentAvgGain) { return true; } else { return false; } } async function fetchInformation(pair, page) { let pastAvgGain = C.AVG ...

The method of altering a menu link in WordPress using jQuery varies according to whether the user is logged in or not

I need to update the last link on my menu. When a user is logged in, it should display a profile link; otherwise, it should show a sign-up link. ...

The communication feature using jQuery and PHP is not saving information to the database

I'm currently in the process of setting up a chat page using jQuery and PHP. However, I've encountered an issue where although the Added echo statement appears after submitting data on my simple form, the information is not actually being added t ...

React-modal triggers the file-explorer upon exiting the dropzone

Within my project, I have implemented a button that triggers a modal to appear on mouse-over. This button is nested inside a dropzone element. https://i.sstatic.net/95dxy.png The issue arises when I exit the modal by clicking (not exiting with the escape ...

Is there a way for me to move a user from one room to another room?

My friend and I both have our own rooms in a session. When I want to send him a message, I need to switch his room to the same one where I am. This is the code snippet for creating my own room with static sessions: socket.on('chat-in', function ...

What could be causing me to see a basic checkbox instead of a toggle switch in my React application?

I've been attempting to create a toggle switch that activates dark mode using Bootstrap switches, but when I save the code, it reverts back to a basic checkbox. According to the documentation, for older assistive technologies, these switch elements wi ...

Utilizing CSS files to incorporate loading icons in a component by dynamically updating based on passed props

Is it possible to store icons in CSS files and dynamically load them based on props passed into a component? In the provided example found at this CodeSandbox Link, SVG icons are loaded from the library named '@progress/kendo-svg-icons'. Instea ...

Toggle the checkbox to either select or deselect the value

I am attempting to toggle the value of a checkbox. When checked, the value should be set to active, and when unchecked, it should be set to disabled. The current code successfully changes text based on the checkbox status, but the issue is that the value ...

Strategies for transferring retrieved data to the getServerSideProps function

I am currently utilizing the Context API to retrieve data and then pass that data to the getServerSideProps function, but encountering the following error: The React Hook "useContext" is being called in a function "getServerSideProps" that is neither a Re ...

Exploring BreakPoints using gridlisttiles

Can Grid List Tile components be configured to occupy the entire screen on small devices using sm={12} lg={6}, but only half of the screen on larger devices? If not, is there a way to adjust the grid list layout to display fewer tiles per row on smaller ...

Access your account using AJAX jQuery authentication

Having an issue with a simple login using ajax. Everything seems to be in order, but I can't figure out what's wrong. I need to notify the client that the user information is correct and then redirect them to the main page. Source Code <!DOC ...

Setting column heights and spacing in Bootstrap

I'm looking to dynamically populate the blocks. Essentially, a for loop would be used to pass the data. However, I'm facing some challenges with the height of the blocks at different screen sizes while utilizing bootstrap 4. My goal is to have th ...

Converting Milliseconds to a Date using JavaScript

I have been facing a challenge with converting milliseconds data into date format. Despite trying various methods, I found that the solution provided in this link only works for a limited range of milliseconds values and fails for higher values. My goal is ...

Display the information in the second dropdown menu once the selection has been made in the first dropdown menu

I've successfully implemented a feature where selecting an option from the first drop-down list populates the second drop-down list accordingly. The HTML code snippet is as follows: <select size="1" id="BodyPart" title="" name="BodyPart"> ...