CSS - starting fresh with animations

I am facing an issue with a CSS animation that I created. Everything seems to be working correctly, but I need to complete it by setting the input type to reset the animation.

Below is the CSS code snippet that should reset the animation:

$('button').on('click', function(){
var heading = $('h1').clone().removeClass();
$('h1').remove();
$('header').append(heading);
$('h1').addClass('fadein_element');

});

CSS Animation Section:

@keyframes fadein {
0%   { opacity: 0; }
100% { opacity: 1; }

.fadein{-webkit-animation: fadein 3s ease-in ;
            -moz-animation: fadein 3s ease-in ;
             animation: fadein 3s ease-in ;

This was my basic HTML snippet for that part:

<input type="radio" name="radio-set" checked="checked" id="st-control-1"/>
<a href="#st-panel-1">WebGear</a> 

And here is the edited version:

input type="radio" name="radio-set" checked="checked" id="st-control-1"/>
<a href="#st-panel-1"><h1 class="fadein_element"><button class="fadein_element">WebGear</button></h1></a> 

I am struggling to reset the animation and could use some help. Besides this issue, everything else is functioning properly. Any suggestions on how to make this work would be greatly appreciated, preferably using default HTML code...

Edit: Sharing minimal code that I am trying to fix

</head>
<body>
<div class="st-container">

<input type="radio" name="radio-set" checked="checked" id="st-control-1"/>
<a href="#st-panel-1">Something</a>

<input type="radio" name="radio-set" id="st-control-2"/>
<a href="#st-panel-2">Happiness</a>

<input type="radio" name="radio-set" id="st-control-3"/>
<a href="#st-panel-3">Tranquillity</a>

<input type="radio" name="radio-set" id="st-control-4"/>
<a href="#st-panel-4">Positivity</a>

<input type="radio"  name="radio-set" id="st-control-5"/>
<a href="#st-panel-5"> WebGear</a>

<div class="st-scroll">

    <section class="st-panel" id="st-panel-5">
        <div class="st-deco" data-icon="H"></div>
<div id="section1"> 
<div id="menu"> <img id="menuitem" src="Images/Menuitem.png"/>
<div id="hlava">
<div id="flashContent">
---Here goes the content---
There are just closing tags

And CSS Styles:

@keyframes fadein {
0%   { opacity: 0; }
100% { opacity: 1; }
}

.fadein{-webkit-animation: fadein 3s ease-in ;
            -moz-animation: fadein 3s ease-in ;
             animation: fadein 3s ease-in ;

When I click on a "radio button," I want my (in this case st-panel-5) to reset the animation. Any of those 5 buttons should trigger this behavior, so I believe I could apply it to the st-panel class.

Answer №1

In order to resolve this issue, you need to hide all the st-panel except for the one that corresponds to the checked radio input by setting display: none; opacity: 0. Then, apply the animation: fadein ...; property to the targeted st-panel-nn ID of the checked radio input.

Next, Try clicking on the first two radio inputs to observe the behavior

#st-control-1:checked ~ .st-scroll .st-panel:not(#st-panel-1),
#st-control-2:checked ~ .st-scroll .st-panel:not(#st-panel-2) {
  opacity: 0;
  display: none;
}

#st-control-1:checked ~ .st-scroll #st-panel-1,
#st-control-2:checked ~ .st-scroll #st-panel-2 {
  animation: fadein 1.5s ease-in;
}

@keyframes fadein {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
<div class="st-container">

  <input type="radio" name="radio-set" checked="checked" id="st-control-1"/>
  <a href="#st-panel-1">Something</a>

  <input type="radio" name="radio-set" id="st-control-2"/>
  <a href="#st-panel-2">Happiness</a>

  <input type="radio" name="radio-set" id="st-control-3"/>
  <a href="#st-panel-3">Tranquillity</a>

  <input type="radio" name="radio-set" id="st-control-4"/>
  <a href="#st-panel-4">Positivity</a>

  <input type="radio"  name="radio-set" id="st-control-5"/>
  <a href="#st-panel-5"> WebGear</a>

  <div class="st-scroll">

    <section class="st-panel" id="st-panel-1">
      <div class="st-deco" data-icon="H"></div>
      <div id="section1"> 
        <div id="menu"> <img id="menuitem" src="Images/Menuitem.png"/>
          <div id="hlava">
            <div id="flashContent">
            Some content 1
            </div>
          </div>
        </div>          
      </div>
    </section>

    <section class="st-panel" id="st-panel-2">
      <div class="st-deco" data-icon="H"></div>
      <div id="section1"> 
        <div id="menu"> <img id="menuitem" src="Images/Menuitem.png"/>
          <div id="hlava">
            <div id="flashContent">
            Some content 2
            </div>
          </div>
        </div>          
      </div>
    </section>

  </div>
</div>

Answer №2

"I have a code snippet that I believe can reset animations, although it is actually written in Javascript using jQuery." - Perhaps there was some confusion on my part.

To use this code after an animation has been completed:

element.offsetWidth = element.offsetWidth;

It seems to be pure Javascript (no jQuery required). In your specific case, it would look like this:
document.getElementsByTagName("h1")[0].offsetWidth = document.getElementsByTagName("h1")[0].offsetWidth

If you need more details, feel free to visit this link.

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

Is it possible to modify the CSS styling in React using the following demonstration?

I am attempting to create an interactive feature where a ball moves to the location where the mouse is clicked. Although the X and Y coordinates are being logged successfully, the ball itself is not moving. Can anyone help me identify what I might be overl ...

Discover the power of utilizing the reduce function to extract the value of a specific field within an array of Objects

In the following example, we have an object with 3 forms: formA, formB, and formC. Form A and B are objects, while formC is an array of objects that can contain multiple items. const object: { "formA": { "details": {}, ...

Accessing and sending only the body part of an HTTP response in Angular 7 test cases: A comprehensive guide

Currently, I am working on creating unit test cases in Angular 7 for a Component that utilizes an asynchronous service. This is the content of my component file: submitLoginForm() { if (this.loginForm.valid) { // send a http request to save t ...

using a tag in flex can disrupt the arrangement of the box's design

What could be the reason for this issue? Is it possible to make the hyperlink appear inline with the rest of the text? .test { padding: 25px; display: flex; height: 100%; text-align: center; font-size: 25px; font-weight: 600; ...

Dealing with the Spread operator in React and Redux causes issues

As a newcomer to the world of React and Redux, I find myself facing compilation errors while working on a reducer due to my attempt to utilize the spread operator. export default function chaptersReducer( state = { chapters: {}, isFetching: false, error ...

Enhancing collapsible list headers in jquery mobile with checkboxes

Having trouble with a jQuery Mobile website issue. Currently working on a jQuery mobile site that includes a collapsible list (). The client request is to have a checkbox inside the header, allowing users to check items off without needing to open them. T ...

Express JS backend causing CSS file to fail to load in React project

After doing some research on Stack Overflow, I came across a few solutions but none of them seemed to work for my specific situation. I am currently attempting to serve my React website from an Express backend server. Here is the layout of my folders: cli ...

Issue with Angular 6 Animation not showing up

Looking to incorporate an animation spinner into my Angular app Found this spinner example: https://codepen.io/z-/pen/OPzNLz spinner.component.html import { Component, OnInit } from '@angular/core'; @Component({ selecto ...

Ways to boost heap capacity in Corb2 for MarkLogic

I encountered a challenge while running my custom deletion framework on a massive dataset. When attempting to execute Corb2, I started receiving the warning below and occasionally even encountered errors due to insufficient memory. WARNING: Slow receive! C ...

What could be causing the vue-property-decorator @Emit to malfunction in my Vue TypeScript file?

I am currently working with Typescript and Vuejs, where I have a child component called child.component.tsx import Vue from 'vue'; import Component from 'vue-class-component'; import { Emit } from 'vue-property-decorator'; ...

Is there a way to link dynamic server fields with VueJS?

How can I bind data posted by the server with Vue.js in order to display the data instead of field names? <script> module.exports = { data: function () { return { filedNameFromServer: ['{{filed1}}' ...

Issue: The initiation function fails to start data

I have created an app using Ionic framework that displays articles. When a single article is opened, I use the init function in the UserService to initialize user data: angular.module('coop.services') .factory('UserService', function( ...

Incorporate keyframe animation into a styled component in material-ui using React

Currently seeking assistance with implementing key frames animation using react material-ui(version ^5.0.0). I am using styled components to style my JSX elements, but encountering errors when trying to incorporate keyframes animation within these styled c ...

Put your username onto the page

Is there a method to retrieve and display text inputs? For example: document.getElementById('input_id') <input type="text" placeholder="username" id="input_id"> and the result will be: document.showElementById('box_id') < ...

Transforming varied JavaScript objects into a serial form

In my application, there is a concept of an interface along with multiple objects that implement this interface in various ways. These objects are created using different factory methods, with the potential for more factories to be added as the application ...

Retrieve a Vue Component by utilizing a personalized rendering method for a Contentful embedded entry

Currently experimenting with Contentful, encountering some issues with the Rich text content field. To customize the rendering of this block and incorporate assets and linked references in Rich text content, I am utilizing the modules '@contentful/ri ...

Guidelines for leveraging AngularJS Decorators to deactivate a button within an Html document

Currently, I am utilizing the blur admin theme and exploring the possibility of using decorators to hide a button without directly modifying the HTML. Despite my efforts, I have been unable to successfully conceal the button. Can someone provide guidance o ...

Testing the number of times module functions are called using Jest

As someone who is relatively new to JavaScript and Jest, I am faced with a particular challenge in my testing. jest.mock('./db' , ()=>{ saveProduct: (product)=>{ //someLogic return }, updateProduct: (product)=>{ ...

Issue with Ajax post redirection back to original page

I'm facing an issue with my ajax call where I send multiple checkbox values to a php file for processing and updating the database. The post request and database updates are successful, but the page doesn't return to the calling php file automati ...

Elements that are hidden or not displayed are still able to receive mouse over events

I am in the process of learning how to handle events within svgs and I have encountered a strange issue. Currently, I am working on an infovis project where I create an interface to display various column-graphs. This part is functioning well so far. Ho ...