Two conditional statements. Both are functional, but only one displays an output

I am currently attempting to rotate a fixed image in synchronization with fullpage.js, and for the most part, it is functioning correctly.

To avoid undesired rotation, I need to stack CSS rotate() values.

The stacking works as intended when scrolling down (e.g., 180, 360, 540, etc.), but it does not work when scrolling up.

Despite trying alerts to check if the calculation is correct, the issue seems to arise from the code related to scrolling up not being displayed in the HTML document.

Below is a snippet of my code:

var rotation = 0,
    rotationInc = 180,
    miniLogo = $('#mini-logo');

$(document).ready(function () {
  $('#home').fullpage({
    verticalCentered: false,
    scrollingSpeed: 300,
    onLeave: function (index, nextIndex, direction) {
      if (direction == 'down') {
        rotation += rotationInc;

        setTimeout(function () {
          miniLogo.addClass('enlarge');
        }, 400);

        miniLogo.each(function () {
          alert(rotation);
        });

        setTimeout(function () {
          miniLogo.css({
            'transform': 'rotate(' + rotation + 'deg)'
          });
        }, 800);

        setTimeout(function () {
          miniLogo.removeClass('enlarge');
        }, 1200);
      }

      if (direction == 'up') {
        rotation -= rotationInc;

        setTimeout(function () {
          miniLogo.addClass('enlarge');
        }, 400);

        miniLogo.each(function () {
          alert(rotation);
        });

        setTimeout(function () {
          miniLogo.css({
            'transform': 'rotate(' + rotation + 'deg);'
          });
        }, 800);

        setTimeout(function () {
          miniLogo.removeClass('enlarge');
        }, 1200);
      }
    }
  });
});

The first "if" statement operates perfectly, while the second one triggers the desired alert but fails to display the reduced degree on the HTML page.

Any assistance in resolving this issue would be greatly appreciated, as I suspect it may be due to a beginner's error.

Answer №1

Here's a suggestion:

initialRotation = 0;
rotationIncrement = 180;
logoElement = $('#mini-logo');

$(document).ready(function () {
  $('#home').fullpage({
    verticalCentered: false,
    scrollingSpeed: 300,
    onLeave: function (index, nextIndex, direction) {

    var currentRotation = (direction == 'down') 
        ? initialRotation += rotationIncrement
        : initialRotation -= rotationIncrement;

        setTimeout(function () {
          logoElement.addClass('enlarge');
        }, 400);

        logoElement.each(function () {
          alert(currentRotation);
        });

        setTimeout(function () {
          logoElement.css({
            'transform': 'rotate(' + currentRotation + 'deg)'
          });
        }, 800);

        setTimeout(function () {
          logoElement.removeClass('enlarge');
        }, 1200);
      }
    }
  });
});

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

Using the Fetch API to send PUT requests in React.js

My GET routes are functioning properly, however, I am encountering an issue with passing data to my PUT route. The method "saveOverTemplate" in the first file is designed to take the content from my component and send it to the PUT route for updating the d ...

The local webpage varies from the online version

After uploading my website to my hosting space, I noticed that the online version looks different from the local version. In my local version, I am debugging with Dreamweaver and checking responsive behavior with Google DevTools. Everything seems fine - ...

Javascript string manipulation operation

Is it possible to extract only the characters 'ABCD' from a string like 'ABCD150117T15' using JavaScript? I am interested in removing everything after 'ABCD' in this example, specifically excluding the first occurrence of a n ...

Encountering a HttpMediaTypeNotAcceptableException while making a jQuery ajax request after upgrading to Spring 3.2.4版本

Whenever I attempt to execute a jQuery ajax call, I am facing the HttpMediaTypeNotAcceptableException. The current configuration that I have includes: Within the context (which is in the classpath), I have the following: <context:component-scan base- ...

Is the Bootstrap popover triggering the same action/event twice?

Have you ever encountered the issue of Bootstrap's popover repeating an action twice? It can be frustrating, especially when trying to submit a form inside the popover's data-content using AJAX. The form data gets repeated twice and the form is p ...

Utilizing SendGrid Java to send dynamic HTML templates via email

Currently, I am utilizing SendGrid in Java to send an email that contains HTML. Within the HTML content are dynamic elements that are requested from the frontend. On the frontend side, there is a text field with spaces and newlines (\n). When I pass t ...

When working with React, it is essential to ensure that each child in an array or iterator has a unique "key" prop in order to access the value of state variables effectively

Can anyone help me with an issue I'm experiencing? I keep getting an error saying that each child in an array or iterator should have a unique "key" prop. Also, when I try to console.log(sTime) in the Chart Provider component, it's returning NaN. ...

Use Typescript in combination with React/Redux to showcase a dynamic table on the

Looking to create a React TypeScript Redux application that showcases a table using an API endpoint provided at https://example.com/users The goal is to construct a table with 4 columns: Name, Email, City, and Company, utilizing the API response to popula ...

Connect HTML and CSS files to your Meteor project

I need to incorporate a pre-existing lengthy form that includes both CSS and HTML files into my current meteor project. How can I achieve this? Is it possible to accomplish it in the following manner: <template name = "premadeForm"> somehow con ...

Guide on aligning two images side by side

Is there a way to align two images side by side and then include a <div> with a smaller width and apply overflow: hidden? Similar to a slider. I keep getting images stacked on top of each other (block level), but I want them inline. * { margi ...

"SelectChange" event for <drop-down menu>

TL;DR How do I monitor changes in the markup of <select> and <option> tags without relying on the .change() event? I am looking for a way to detect any modifications in attributes (disabled="disabled"), values (value="foo" ...

Mysterious additional spacing

I am facing an issue with aligning my div elements with a 20px margin. Despite setting the margin to 20px, I notice that there are additional 4 pixels rendered when I view it on the browser. Below is the code snippet: .block{ width:50px; height:50 ...

What measures can be taken to prevent the reloading of a subfolder within the same parent in the Fuel

var DataSourceTree = function (options) { this.source = options.source; } DataSourceTree.prototype = { data: function (options, callback) { var self = this; var ...

Having trouble loading an image with texture loader in Three.js? The issue may be related to the size and scale of the plane geometry

Can someone please assist me with loading images using TextureLoader? I am encountering a major issue where I am unsure how to add images to a mesh in a 1:1 scale and calculate PlaneGeometry. My goal is to display the loaded image in its original size with ...

Tips for hiding a table row in ASP Listview utilizing CSS

Can anybody help me understand why my ListView is ignoring the css properties applied to the div in the markup below? <ItemTemplate> <tr> <td><%# Eval("RowNumber")%></td> <td><%# Eval("Desc")%&g ...

Attempting to implement CSS styles tailored specifically for a webpage that is dynamically loaded using AJAX

I'm experimenting with loading CSS for AJAX pages so that the styles are contained within each individual page instead of one large CSS file. My current approach is something like the following: $("#content").load(pageid+".html #content > *", func ...

Struggling to display array values in the console log outside of a loop?

After I push the array outside of the loop with (cpu_usage, timestamp, and clientID), now I want to read the values of clientID on the console log using console.log(result[0][2]);. However, I am getting an error that says "Cannot read property '2&apos ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

Utilizing a dynamic value in an Angular directive

For my latest project, I am working on developing a basic JSON pretty-printer directive using angular.js. Here is the code snippet I have so far: (function(_name) { function prettyJson() { return { restrict: 'E', ...

If the condition has a class name of condition, then display

Having performance issues due to slow data rendering with each tab using a partial view. The code snippet for each tab is as follows: <div class="tab-content" ng-controller="MyController"> <div id="tab-1" class="tab-pane fade active in " ng-i ...