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

Transferring information from a function-based module to a higher-level class component in React Native

I'm currently working on an application that has a tab navigation. One of the screens in the tab is called "ScanScreen," where I'm trying to scan a UPC number and send it to the "HomeScreen" tab, where there's a search bar. The goal is for t ...

What is the best way to halt a specific function in jQuery?

I recently developed a website for my photographer friend, and I implemented a feature where the home page is initially blurred. Visitors can click a button to unblur the content. While the functionality works smoothly, there's one issue - every time ...

Organizing AngularJS controllers in separate files

I am facing a challenge with my cross-platform enterprise app that is built using Onsen UI and AngularJS. The app has been growing rapidly in size, making it confusing and difficult to manage. Until now, I have kept all the controllers in one app.js file a ...

How can I display a badge in my app when it is running using React Native?

For the past week, I've been dealing with an issue. My question is how can I display a new message badge without having to click on the message room when running my app. The badge should only show up after clicking on the message room. I see the badg ...

Events trigger React to render multiple times

I have implemented socket functionality on my website where users can send a word to the server, triggering an event (art-addpic) that broadcasts an image URL corresponding to that word to all users. However, only users with isArtist=true are allowed to re ...

Replace specific text with a span element around it?

I am working with the following HTML code: <p class="get">This is some content.</p>. My goal is to modify it so that it looks like this: <p class="get">This is <span>some</span> content.</p>. To achieve this, I have ...

tips on utilizing the JSON information transmitted from the backend

$.ajax({ url: '{{ URL('reports/groupsUsersGet') }}', dataType: "json", data: { group_id : $('#group').val(), }, success: function(data) { <li>"i need to insert variable here"</li> }, error: function (data) ...

Height not being generated by Div element

I am encountering an issue with a div element that contains an h2 and three nested div elements. Despite not explicitly setting a height for the container div, it is not expanding to accommodate the varying heights of the inner divs. This problem is causin ...

Issue encountered while attempting to install the node-jasper package

I'm encountering an error stating that python.exe is not found, despite having installed Python and added it to the environmental variables. I've also attempted using Node versions 8, 10, and 12 without success. I tried installing node-jasper fo ...

Disable user interactions on OpenLayers map during animation execution

I am currently developing a web application that incorporates an OpenLayers map feature. Within this component, I extract properties from its parent to display icons on specific coordinates on the map. As this process can take some time, I have implemented ...

Issue arises when combining inline-block and overflow-wrap for div elements

I am facing an issue with two divs that look good on the same line when utilizing display: inline-block. However, if one of the containers contains an excessively long word that I attempt to wrap using overflow-wrap and word-break, it causes the container ...

What is the process for assigning specific tags to specific items within an array?

As I navigate through a list of students, I am encountering an issue with my tag functionality. Currently, when a student adds a tag to their container, it is being added to every student's tags instead of just the intended student. How can I modify t ...

Is it possible to refresh AdSense banner when the router changes?

Is there a way to reload the AdSense banner ads when the router changes? I've been encountering issues trying to re-add the script and HTML properly. Any guidance on how this should be done would be greatly appreciated... This is just a test for one ...

Ending asynchronous tasks running concurrently

Currently, I am attempting to iterate through an array of objects using a foreach loop. For each object, I would like to invoke a function that makes a request to fetch a file and then unzips it with zlib, but this needs to be done one at a time due to the ...

Unusual behavior observed while looping through an HTMLCollection returned by the getElementsByClassName method

After spending some time debugging, I discovered an issue with my function that changes the class of elements to modify their properties. Surprisingly, only specific elements were being affected by this change. It took me a while to troubleshoot and resolv ...

Try employing an alternative angular controller when working with the bootstrap modal

I am trying to implement a bootstrap modal in my main HTML file, and I need some help on how to call another Angular controller for the modal. The button that triggers the modal is within a div that already has an Angular controller, and this is causing th ...

Tips for creating responsive scrollable columns in an HTML table with Bootstrap

I'm not a professional web designer. I attempted to create a web layout with scrollable columns containing data in anchor tags that are loaded dynamically. To achieve this, I created an HTML table structure along with a stylesheet. Here is the source ...

Troubleshooting a JavaScript error while attempting to execute a function from a

I have been working on a new JavaScript library named TechX. Check out the code snippet below: (function(){ function tex(s){ return new tex.init(s); }; //initiate the init selector function tex.init = function(s ...

Changes have been made to the Vue object, however, it does not trigger a re-render

Whenever I hit the right arrow key, it adjusts the object without re-rendering it : <div class="map"> <div class="map-page" tabindex="0" @keyup.arrow-keys="show" ref="mapPage"> <template v-for="mapRow in mapMatrix"> < ...

Issues with SocketIO message reception in JavaScript

My current project involves setting up a FlaskSocketIO with socket.io.js application to facilitate real-time communication between the frontend and my web socket server. Here is a snippet of the frontend code: $(document).ready(function() { name ...