Turning off and on CSS transitions to set the initial position

Is there a way in javascript to position divs with rotations without using transitions initially for an animation that will be triggered later by css transition? I have tried a codepen example which unfortunately does not work on the platform but works fine locally due to window.onload not being considered. Here is the link to my codepen: http://codepen.io/3MO/pen/ZLoKbv

In my approach, I do not set any transition attributes for the divs at first. I transform the divs based on the digit clicked and then add a class to activate the transition properties after this initial positioning.

function onThumbnailClick(event) {
   var index = parseInt(event.target.id.split('-')[1]);

   //initialize the div position without transition :
   initPortraitPanel(index); 
   //then I "activate" the transition :
   $('.portraitDiv').addClass('active-transition'); 
   //After that I want to start transitions...
}      

.active-transition {
      transition: 0.5s;
}

The issue arises when setting the initial positions of the divs taking into account the transition properties even though they are defined after. Can anyone suggest a proper method to disable the transition during the initial positioning and activate it afterwards so that the initial positioning does not use the transition effect?

Your help would be greatly appreciated! Thank you.

Answer №1

Implementing a timeout in the addClass method:

function handleThumbnailClick(event) {
    var position = parseInt(event.target.id.split('-')[1]);

    displaySelectedImage(position);
    $('.imageContainer').setTimeout(addClass('zoom-in'), 50);
}

Check out the code on CodePen

It appears that someone previously provided an answer to this question, which was then downvoted and removed...the reasons remain unclear.

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

Converting an unbroken series of string values into organized key-value pairs for easy reference

I assure you this is not a duplicated question. Despite my attempts with JSON.parse(), it seems to be ineffective. Here's the issue at hand: I recently received assistance from an answer that was both crucial and enlightening. However, the code prov ...

Unpacking objects within an array in the backend of a Next.js application

How can I resolve this issue? I am passing the req.query parameter with an array but I am unable to destructure or use items from the array. In my Next.js API backend, I only get [object Object] or undefined. How can I access and select specific values fro ...

The evolving impact of the HTML5 <video> element

I've been attempting to find information on this topic, but unfortunately my search has not been very successful. I vaguely recall coming across a tutorial that covered something like this. Does anyone happen to know how to alter the perspective of a ...

Node JS GET request using fetch stops displaying console outputs after a certain duration

I am currently working on building a calendar application using node, mongodb, html, css, and javascript. The main goal is to allow users to input dates as events which can be displayed dynamically. I am facing an issue where, upon trying to retrieve these ...

Customize material-ui button designs using styled-components

I'm currently facing an issue with overriding the border-radius of a material-ui button using styled-components. Despite setting it to 0, it's not taking effect. Here is the code snippet: import React from "react"; import styled from "styled-co ...

Encountered an error while executing findByIdAndRemove operation

Could someone please assist in identifying the issue with the mongoose findByIdAndRemove function in the delete route provided below? //DELETE Route app.delete("/blogs/:id", function(req, res){ //Delete blog Blog.findByIdAndRemove(req.params.id, funct ...

What causes my Excel file to become corrupted when inputting new data?

My intention with this code is to insert "ABC" into cell B3 of an existing Excel document. However, when the file is written, its size decreases significantly and Excel is unable to open it. const excel = require("exceljs"); const template = "./myexcel.xl ...

Python: parsing comments in a cascading style sheet document

I am currently working on extracting the first comment block from a CSS file. Specifically, I am looking for comments that follow this pattern: /* author : name uri : link etc */ and I want to exclude any other comments present in the file, such as: /* ...

The automated Login Pop Up button appears on its own and does not immediately redirect to the login form

Hey guys, I'm struggling with modifying the jquery and html to ensure that when the login button is clicked, the login form pops up instead of displaying another login button. Another issue I am facing is that the login button seems to pop up automati ...

Dealing with Unhandled Promise Rejections in Express.js

I'm providing all the necessary details for this question, however I am confused as to why my callback function is returning an Unhandled Promise Rejection even though I deliberately want to catch the error: (node:3144) UnhandledPromiseRejectionWarni ...

Vue.js will trigger the updated() method only when a particular array undergoes changes

Working on a chat feature and looking for a way to automatically scroll to the end of the conversation when new messages are added. The current solution involving the updated() function works well, but there's a complication with a vue-timepicker com ...

What is the best way to deactivate certain JavaScript functions on my webpage when accessed through a mobile device?

Is there a way to disable specific JavaScript functions when accessing my website from a mobile device? While I can achieve this using CSS only, certain buttons require JavaScript functionality. Below is the internal JavaScript code: var menuBtn = docume ...

Can you import folders containing *.vue files in your project?

Repeating code is my least favorite thing. Currently, I am importing vue files in a repetitive manner in my main.js file. import Default from '../../src/components/default.vue'; import Home from '../../src/components/home.vue&apo ...

What is the best way to create a loop using JSON information?

Seeking assistance to create a loop using JSON data to display the title, link, and description of advertisements in HTML format. Provided is a JSON template with two ads, but my actual JSON contains 10-20 IDs. What am I overlooking in the code below? Sto ...

Mouseover Magic: Text and Captions Come Alive with JQuery

I am trying to create a rollover effect that displays text when the user hovers over an image. Despite researching numerous tutorials, I have found limited resources on incorporating text or captions using jQuery. Most of the available tutorials focus on C ...

Refresh PHP Calculator Display Once Results are Shown

Currently working on a basic calculator project coded in HTML, CSS, JS, and PHP. Here is a glimpse of it: The user input retrieval is handled by JS, while the actual calculations and result display are taken care of by PHP. I am striving to clear out the ...

Issue regarding Jquery widget

I am working with a widget that looks like this $.widget("ui.myWidget", { //default options options: { myOptions: "test" }, _create: function () { this.self = $(this.element[0]); this.self.find("thead th").click(fun ...

Utilizing Chart.js for generating a sleek and informative line graph

After executing a MySQL query, I obtained two tables named table1 (pl_pl) and table2 (act_act) with the following data: table1: label act_hrs Jan-19 7 Feb-20 8 Mar-20 9 table2: label pl_hrs Mar-20 45 Apr-20 53 I am looking to create a line cha ...

Ways to present a pop-up dialog box featuring word corrections

I have developed a word correction extension that encloses the incorrect word in a span element. Upon hovering over the word, a drop-down menu with possible corrections should be displayed. However, my current code is not functioning properly. How can I en ...

Mozilla browser experiencing issues with mouse move event functionality

Here, I have a background image on the body and with the following script, when the user moves the mouse, the image in the background also moves. body { background-image: url('../images/1.png'); background-size: 98%; background-posi ...