div rotates once in a never-ending jquery loop

I am experiencing an issue with a div item in a table as I attempt to rotate it using JavaScript. The rotation works correctly the first time the function is executed, but subsequent calls do not result in flipping the div.

My goal is for the div to flip each time the function is called. How can I achieve this?

Css:

.box-1{
    transform: rotateY(180deg);
    display:none;
}

JQuery:

function startSlidecat1(started) {
  for (var i = 0; i < footwear.length; i++) {
    var image = footwear[i][0];
    imgslidercat1(image, i * 2100, i == footwear.length - 1);
  }
};

function imgslidercat1(image, timeout, last) {
  window.setTimeout(function() {
    document.getElementById('flip-1').style.display = 'none';
    document.getElementById('category-1').style.display = 'block';
    document.getElementById('category-1').innerHTML = "";
    var product = document.getElementById('category-1');
    var elem = document.createElement("img");
    product.appendChild(elem);
    elem.src = image;
    if (last) {
      flip();
    }
  }, timeout);
}
startSlidecat1();

function flip(){
    $('#category-1').delay(100).css('display', 'none');
    $('.box-1').delay(100).css('display', 'block');
    $('.box-1').transition({
        perspective: '100px',
        rotateY: '360deg'
      },200)  
    setTimeout(startSlidecat1, 2000);
  }

Answer №1

When the div is first flipped, the value of rotateY changes from 180deg to 360deg, which is visible. However, on subsequent flips, it remains at 360deg and nothing happens. To fix this, you just need to reset the value each time the function is called like so:

$('.box-1').css({transform:'perspective(100px) rotateY(180deg)'});

You can add this inside the startSlidecat1 function as shown below:

function startSlidecat1(started) {
  $('.box-1').css({transform:'perspective(100px) rotateY(180deg)'});
  for (var i = 0; i < footwear.length; i++) {
    var image = footwear[i][0];
    imgslidercat1(image, i * 2100, i == footwear.length - 1);
  }
};

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

My website is optimized for desktop and tablet viewing, but unfortunately it is not responsive on mobile devices. Can you advise on how to fix

I recently completed a portfolio website using HTML, CSS, Bootstrap 4, and jQuery. While the site displays properly on the browser and up to tablet mode, I encountered issues when viewing it on my phone. There seems to be a blank area that can be scrolled ...

Guide on embedding a form component within an iframe using ReactJS

I am trying to figure out how to render my form component inside an iframe, but so far it's only rendering the iframe itself. Any tips on how to accomplish this task? import './App.css'; import ReactDOM from "react-dom/client" impo ...

Is there anyone who can take a shot at creating this calendar widget using HTML/CSS? I'm struggling to code it myself

I have been assigned a task to create a calendar widget using HTML and CSS, but I'm struggling to figure out the structure with tables or divs. Here is my design for the calendar: Here is how I've attempted to design it so far: You can view the ...

Java Script Event Handling Creating Array with Numerous Duplicates

While attempting to recreate the Simon game, I am working on adding click events to an array and testing that Array in a nested function immediately. Initially, everything seems to be functioning correctly. However, after the third run, the array does not ...

Unable to set DIV to 'inline-block' or none based on checkbox selection

Despite reviewing multiple examples, I am still struggling to make this DIV visible and hidden by clicking a checkbox. Can someone please review my JavaScript code? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Conten ...

JavaScript code that iterates through all files in a designated folder and its subfolders using a for loop

I am looking to combine two JavaScript scripts into one, but I'm not sure how to do it. The first script uploads files from a specified folder to VirusTotal for scanning and returns the scan result. The second script lists all files in the specified ...

At what point is the JavaScript function expression triggered in this code snippet?

let express = require('express') let app = express(); app.use(express.static('static')); let server = app.listen(3000, function() { let port = server.address().port; console.log("The server has started on port", port); }); I ...

When using Codeigniter with AJAX dropdown menus, some issues may arise if form validation fails and the view gets redirected or reloaded

After the validation process fails and redirects back to the same controller index, an issue arises where the second dependent dropdown stops functioning. if (!$this->form_validation->run()) { $this->index(); } The form consi ...

Finding the difference between two collections in MongoDB using the Diff() method

After conducting my own research, I realized that the existing solutions to similar questions did not quite match what I was looking for. Therefore, I decided to create a new question. When it comes to Javascript, what is the most effective method for com ...

Display a notification to the user prior to reloading the page

I have created a code for logging attendance at work using a barcode reader. The user simply needs to scan their card with a barcode to register their attendance. let $scannerInput = $(".scanner-input"); $(document).ready(function(){ $scannerInput.focu ...

Unable to send State from parent Component to Child (state counter for pomodoro clock)

Hi everyone, I am relatively new to React and currently working on building a Pomodoro Clock. However, I have hit a roadblock while trying to get the buttons + and - to update the numbers set in my State. Here is what I have in my Main App Component: clas ...

Unexpected Timed Out error from Socket.IO adapter when MongoDB connection is lost

I have been experimenting with capturing the disconnection event in mongodb. Everything is working smoothly with this setup: simple.js 'use strict'; var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:2701 ...

declaring a variable in JSP and incorporating it into jQuery

How can I retrieve the size of options in a route object and store it in a variable in JSP? I then need to access this variable in jQuery. Any suggestions on how to achieve this? JSP code : <%!int loopSize = routes.get(0).getOptions().size(); %> ...

Utilizing multiple components onEnter with React-router for authentication scenarios

I am currently working on an app that consists of 2 components for a single path. The routes are as follows: <Router history={hashHistory}> <Route path="/" component={AppContainer} onEnter={requireEnter}> <Route path="/homepage" ...

Is it possible to utilize scrollTop without the need to create a separate function?

I am currently facing an issue with my jQuery code and was searching for some answers on how to enhance my existing slideDown function. One particular question from 2010 caught my attention, you can find it here: http://stackoverflow.com/questions/4034659 ...

seamless blend of canvas distortion and gradual appearance of particles

Take a look at my work in progress on jsfiddle: https://jsfiddle.net/vzrandom/fkho6grf/8/ I'm experimenting with simplex-noise.js and dat.GUI to add movement to particles. Every 5 seconds, a simulated click occurs on the canvas triggering the start ...

What is the solution for the issue of encountering an undefined key array email while attempting to log in through the form?

I encountered an issue while working on a login form that communicates with the database using PHP at the backend. Even though I have verified the correctness of my login credentials, I am facing an error related to undefined array keys 'email and pas ...

Is it possible to return a promise within the .then function in AngularJS?

I have a unique service called "usersService". I want to create a special method that interacts with another custom service I built. This other service has two handy methods: getUser() and getCurrentUser(). The getCurrentUser() method relies on the injecte ...

Issues with Angular $watch causing mismatches in bindings更新(binding)

I am attempting to set default values for certain model properties by using $watches. I cannot utilize the typical two-way binding because I want the model properties to start off as empty. Although the $watches are successfully setting the properties, the ...

Steps for updating the text of a dropdown button to display the name of the selected item:

I have been searching for a clear answer to this question, but I couldn't find one. So here I am seeking help: I have a button that functions as a dropdown menu: <body> <div class="dropdown"> <button onclick="changeDropdownVisibilit ...