I prefer that my appearance doesn't revert back once styles have been applied

I am experiencing an issue with an image that I placed on my website. Here is what I have tried.

#mysecond
{
width:100px;
height:100px;
background:none;
position:relative;
animation:mysecond 5s;
-webkit-animation:mysecond 5s; /* Safari and Chrome */ 
-moz-animation    : mysecond 5s;
-o-animation      : mysecond 5s;
animation         : mysecond 5s;
}
@keyframes mysecond 
{
from {
transform : scale(1.5);
opacity   : 1;
}
to {
transform : scale(0);
opacity   : .0;
}
}
@-webkit-keyframes {
from {
transform : scale(1.5);
opacity   : 1;
}
to {
transform : scale(0);
opacity   : .0;
}
}
@-moz-keyframes {
from {
transform : scale(1.5);
opacity   : 1;
}
to {
transform : scale(0);
opacity   : .0;
}
}    

After applying this code, my intention was to make the image scale and disappear. However, it scaled and disappeared momentarily but then reappeared after the full 5 seconds. Any suggestions on what I may have done incorrectly?

Answer №1

Start with the end state first.

#mysecond{
 width:100px;
 height:100px;
 background:none;
 position:relative;
 -webkit-animation:mysecond 5s;
 /*missing*/
 -webkit-transform:scale(0);
 opacity:0;
}

Check out this Demo:

http://jsfiddle.net/agj7z/2/

If you want to hide it after an event, remember to change the class:

Hide after 2 seconds

JS

window.setTimeout(function(){
 document.getElementById('mysecond').classList.add('hide');
},2000);

CSS

#mysecond{
 width:100px;
 height:100px;
 background-color:red;
 -webkit-transform:scale(1);
 opacity:1;
}

#mysecond.hide{
 -webkit-animation:mysecond 5s;
 -webkit-transform:scale(0);
 opacity:0;
}

@-webkit-keyframes mysecond{
 0%{
  -webkit-transform:scale(1);
  opacity:1;
 }
 100%{
  -webkit-transform:scale(0);
  opacity:0;
 }
}

Take a look at this Demo:

http://jsfiddle.net/agj7z/3/

Feel free to ask if you have any questions.

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

Struggling to make `align-items="baseline"` function properly

I'm encountering an issue with alignment in my sandbox project. Specifically, I want the bottom of texts with different font sizes to be on the same y axis but I can't seem to figure out how to make it happen. Check out this picture to see exact ...

Ensuring the sidebar stretches to fill the entire page height

Everything was going smoothly in my blog-like layout until I decided to introduce a simple and minimalist User dashboard with a sidebar that deviated from the existing structure. I managed to extract most of the CSS code from the large file generated by H ...

Place a material-ui React component at the center of a footer section

I'm facing a challenge with centering a material-ui Simple Breadcrumbs component within a footer as opposed to having it aligned to the left. Even though I'm new to this, I thought it would be straightforward but I can't seem to figure it ou ...

Issue with mouseover in the jQuery area

As I navigate through a WordPress website, I am attempting to create a mandala using dynamic images. Utilizing jQuery and CSS areas, I aim to display the corresponding image when hovering over a specific section. However, I am facing an issue where there ...

Button in Angular gets stuck when a touchscreen is long pressed

In my Angular2 application, I am facing an issue with a button when running on a Windows 10 touchscreen PC in Chrome. Normally, the button works fine and executes the click function. However, if the button is held for 1-2 seconds, it gets stuck and fails t ...

The significance of !important declarations within media queries

I am currently utilizing zurb foundation. The issue I am facing is that regardless of the viewport size, the body background color always remains red when using the code below: @media only screen and (min-width: 64.063em) { .body {background: red;} } @me ...

How can you modify the Bootstrap width to activate the responsive design?

I currently have the following HTML code snippet: <!DOCTYPE html> <html lang="en> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale= ...

Expand the contents inside a div without affecting the actual div

Is there a way to zoom out the contents of a div similar to how a browser zooms out a page? I'm working on an application that loads a page into a div. However, I want to load the content without scroll bars. This would require zooming out the conten ...

CSS animations made easy - Using a single keyframes declaration to switch animation direction

Is it possible to animate a div to the right when a button is clicked, then animate back to the left with just one keyframes declaration by swapping classes? While attempting this in CodePen, I encountered an issue where the div snaps back after the first ...

Animating the size of an element with dynamic content

I am working on a feature where clicking on a card should display a summary. When a new summary is shown, I want the summary container to animate and align its position with the associated card (top). However, despite my efforts, I am facing an issue whe ...

Text on Bootstrap buttons does not adapt to different screen sizes

https://i.sstatic.net/9Hc9w.png I've been struggling to make the button text responsive, but all my attempts have failed. Below is the HTML code I've been using: <button style="margin-top : 5px;" type="submit" class="btn btn-primary ...

DIV being obstructed by an IFRAME

I am facing an issue with my ASP.NET site where I have used an Ajax Control Toolkit Animation Extender to animate a div flying out, which contains a simple treeview. Upon selecting a node in the treeview, a protected sub is triggered, setting the source o ...

Learn how to easily incorporate a drop-down list into the material-UI Search component within the navbar to enhance the search results

I integrated a Material UI search bar into my React app's navbar following the instructions from the official documentation on MUI. However, the article does not provide any guidance on how to add a dropdown list when selecting the search input field. ...

How can we reduce the use of !important in SCSS when working with React and Material UI?

In my current project, I am developing a Select component in React with Material UI. The CSS styling for the component is managed through an external SCSS sheet imported into the script file. While working on restyling the component, I found it challengin ...

Adjust the width of columns using HTML and CSS

UPDATED: Here is a real-life scenario I am facing: I am trying to adjust the width of columns in my table using inline CSS. Let me provide you with an example: The Table was initially set to 100%, like this: <table width=100% ...> The total number ...

React does not support having two :focus selectors on a single JSX element

I'm working with a React script that includes a specific element. I want to apply more than one :focus-within selector in CSS, but for some reason only the dropdown selector is being expressed when I focus on the element. Here's the code: React J ...

Trouble with Bootstrap Modal not closing properly in Chrome and Safari

ISSUE: I'm facing a problem where clicking on the X (font awesome icon) doesn't close the modal popup as expected. https://i.sstatic.net/yXnwA.jpg LIMITED FUNCTIONALITY ON CERTAIN BROWSERS: Currently, the X button for closing the modal works o ...

Can the CSS property of a class be altered in real-time with jQuery?

I am working on a project where I have a predefined CSS style in one class. I am currently attempting to load that page as an IFRAME on another website. My goal is to modify the CSS property of that specific class from the loaded site using jQuery. Unfor ...

Styling an input text using CSS and Jquery without relying on a parent

Styling CSS input text without a parent div Hello everyone, I am looking to remove the <div id="input_container"> from the code below. Is it possible to achieve the same result without that surrounding div? Check out the jsfiddle: http://jsfiddle.n ...

The presence of Bootstrap remains hidden unless space is designated for it

Question about Bootstrap 5.1.3: Is there a way to hide elements on a page using the bootstrap class ".invisible" without allocating space for them? Currently, when the elements are set to visible using the class ".visible", they occupy space on the page ...