Tips on incorporating fade CSS design and image into each switch statement modification

This app aims to demonstrate the impact of donations to charity by showing users the possible results. For example, inputting $10 could display "provide clothes for starving children".

To enhance the user experience, I would like to add styling that includes a fading effect on the end result display. Currently, when the input is changed to a new number, the text in id="text-result" switches without animation.

Additionally, I want to implement the ability to include different images based on changing switch statements.

Thank you!

HTML

<p> If you donate <input type="text" id="donation" value"3" onchange="imag()"> </input>, you could provide <a id="text-result"></a></p>

CSS

body {
  background-color: #a3d5d3;
}

#text-result {
  opacity: 0;
  transition: 2s;
}

JS:

function imag() {
  var x = document.getElementById("donation").value;
  var text;
  var picture;

  switch (true) {
    case x <= 10:
      text = "clothes to starving children";
      break;
    case x > 10:
      text = "clothes to adults";
      break;
  }

  document.getElementById("text-result").innerHTML = text;
  document.getElementById("text-result").style.opacity = 1;
}

Check out the codepen here: https://codepen.io/keifreelancing/pen/ExagzxP

Answer №1

The reason it doesn't gradually appear again is because once the opacity is set to 1, it remains at that level unless specifically changed. To make it fade back in, you would need to decrease the opacity. One way to achieve this is by using a setTimeout() function. You can find an example of this in action here: https://codepen.io/Klammyq/pen/xxbENQX.

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

Error persists: Attribute value remains ineffective post text input modification

When I click on an icon, the text input fields are filled with values using .attr("value", xxx) based on the clicked item. This functionality works perfectly fine, however, if I manually type something in the text field afterwards, the .attr methods stop w ...

Issues with the Bootstrap navbar toggle functionality

Hello there! I hope you're doing well. I've been following the Bootstrap 5 tutorial on Traversy media's YouTube channel, but I'm encountering an issue with the nav toggler. The nav is not showing up for me and I can't figure out wh ...

Encountering a glitch while iterating through function results in failure after the initial modification

I am facing some errors with the script provided below: var sections = ["#general_info", "#address_records", "#employment_history", "#driver_experience", "#military_experience", "#eeo_survey", &qu ...

An issue arose during the page prerendering process for "/" on Vercel | Next.js resulting in a deployment error

When attempting to deploy my website using Vercel and generating static pages, I encountered the following error in the logs: info - Generating static pages (0/6) Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/ ...

No data found in response from gRPC Server

Despite my efforts, the JSON object returned from a callback in my gRPC server remains empty. Following a tutorial similar to this one, I have made some modifications such as using a SQLite3 server instead of knex and focusing on the listProducts method. ...

What is the most effective method to activate OnClientCommand from the server's perspective?

I've found myself in a bit of a dilemma - it seems that solving this issue will require some restructuring of my code. The situation involves a server-side timer running that needs to emulate clicking a tab on a RadTabStrip. On the client side, I hav ...

Tips for removing yellow box decorations

I've noticed a yellow outline appearing on many of my input boxes when I select them. How can I remove this? Css lint is reminding me that: *:focus { outline: none; } should not be used due to outlines should not be hidden unless other visual chang ...

What is the best way to retrieve an object within an array using ng-repeat?

I'm encountering an issue with using ng-repeat in my development project. I am working with Ionic 2, utilizing TypeScript and HTML5. I have created an array of Objects where I need to access its attributes. The error message "cannot read property c.ge ...

Include the insertion button in the Tiny MCE Editor

Currently, I am in the process of developing my own plugin to integrate into the list of TinyMCE v4 plugins. So far, I have successfully added a button to the menu that opens a pop-up when clicked. In this pop-up, users can input data which is then added t ...

Rendering with Apache Tiles 3.0

Encountering an issue with rendering HTML in Apache Tiles 3.0. I have noticed that when viewing the HTML code below in a browser, the table displays correctly without any space between the first and third td elements. <html> <head> <title& ...

"Encountering an error: unable to call the Firebase function as the httpsCallable is

I am currently working on implementing role-based authentication using Firebase auth and Firebase functions. I have successfully set up a registration form, but now I am facing an issue while trying to add a form that allows users to submit an email which ...

AngularJS: Choosing items from a dropdown menu, not an object or array

Need help creating a select list from a simple list, not an array or object with keys. All the resources I've come across are focused on keyed data types. $scope.numbers = ['tweedle', 'beetle', 'battle']; With the follo ...

Identify mistakes within a document

I have created a fiddle that includes the following code: http://jsfiddle.net/nGnbJ/7/. The fiddle uses Bootstrap Wizard to create tabs. I am looking for a way so that when the user submits the form from the submit button on the third tab, it checks all th ...

What's the best way to pinpoint the value of a heading tag?

Is there a way to target the value of an h2 tag, similar to how you would with an input field? const [text, setText] = useState("") <input type="text" onChange={(e) => setText(e.target.value)} /> I attempted <h2 onChange={(e) => setCheck(e ...

Removing specific text from a textarea containing a vast quantity of information

I developed a simple XML formatter using HTML and Javascript. I am looking to incorporate a delete feature into it. Essentially, I want the ability to remove an entry without affecting any other data. <contact <!--Jane Smith--> first_name="Jane" ...

Discover how to extract a whole number (and *exclusively* a whole number) using JavaScript

Is it possible to convert a string to a number in a way that only integers produce a valid result? func('17') = 17; func('17.25') = NaN func(' 17') = NaN func('17test') = NaN func('') = NaN func('1e2& ...

Exploring the efficiency debate: CSS, JavaScript, and jQuery on performance

As someone new to the world of web design, I work with CSS, JavaScript, and jQuery for developing websites. There are instances where a certain effect can be created using all three. For example, a basic mousehover effect can be accomplished with CSS :hov ...

Encountering issue with express 4.x bodyparser functionality

I recently updated my body-parser to the latest version (1.17.1) and made sure to organize my code as advised by others. import express import body-parser app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended : fa ...

Designing the appearance of a jQuery UI range slider

I recently delved into the world of jQuery UI for the first time, and let me tell you, it's been quite the challenge. I've been attempting to create a slider that looks like this: https://i.sstatic.net/YZ3gM.png However, I'm struggling to c ...

Moving a particle along the surface of a sphere using three.js geometry

Here is the code snippet I've been working on. Currently, my goal is to position a single particle on a sphere. How can I combine particles and sphere geometries together? Once this combination is achieved, I aim to dynamically render particles on top ...