By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – transition is not adding up in img created by JavaScript
JavaScript

Javascript – transition is not adding up in img created by JavaScript

Admin
Last updated: 2023/12/13 at 5:56 PM
Admin
Share
2 Min Read
transition is not adding up in img created by JavaScript

Problem:

When i am clicking on a character it should be added in ‘Animated-Pokemon’ span but with transition but the transition is not being applied

Contents
Problem:Solution:

this is my HTML where the image should be created

 <div class="Pokemon-Area">
                        <span id="poke1" class="Animated-Pokemon">
                        </span>
                        <img src="../Pokemon-Images/game.png" alt="logo" width="40%" id="logo-Img1">
                    </div>

and this is my CSS code

.Animated-Pokemon{
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
   left: -30;
   opacity: 1;
  transform: scale(0.3);
  transition: opacity 0.3s, transform 0.5s;
}
.Animated-Pokemon.show{
    opacity: 1;
    transform: scale(1);
    
}
.Animated-Pokemon img{
width: 14vw;
}

and Js code

function handlePokemonClick(pokemonName) {
  const imageName = pokemonName.replace(' ', '_'); 
  const imagePath = `../Animated-Img/${imageName}.gif`;

  const animatedPokemon = document.createElement('img');
  animatedPokemon.src = imagePath;
  animatedPokemon.alt = pokemonName;
animatedPokemon.classList.add('show');


  for (let i = 1; i <= 6; i++) {
    const slot = document.getElementById(`poke${i}`);
    if (slot.children.length === 0) {
      slot.innerHTML = '';
      slot.appendChild(animatedPokemon);
      slot.style.display = 'block';
      break; 
    }
  }
}

when the image is created it should add show class applying transition to the image (I have put the opacity in Animated-Pokemon to 1 because with 0 its not showing because theres no transition)
but when i move from one program to chrome i can see the transition but not when its clicked

I tried everything but nothings working it was working when the img was singular Help me out please

Solution:

It looks like you add the show class when you create it. This way there is nothing to transition from. Either you need to add the element before, and adding the Show class later when you want to apply the transition, or you need to add a keyframes animation like this:

.Animated-Pokemon{
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1
  }
}

Here is a working example: JSFiddle

Hope this helps. Cheers

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Make img fill entire height [closed] Javascript – Make img fill entire height [closed]
Next Article Prevent unchanged children from re-rendering in React Javascript – Prevent unchanged children from re-rendering in React
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?