Steps for creating a fade-in effect using CSS on an input set that is displayed as a block

I can't seem to figure out a solution for my current issue. I want my inputs to be hidden with opacity: 0 on page load and then appear later with full opacity, but only if they are displayed in block format in order to move down the page instead of inline. However, setting them to block seems to interfere with the fade-in effect that is applied using the .block class. Is there a way to make the inputs display as block elements while still being able to fade in using CSS?

Furthermore, I am trying to find a way to make the labels/inputs appear as block elements so that the label is positioned above the input field and both elements are centered on the page. Is this possible within the given example?

You can see the issue demonstrated in this fiddle.

$(function() {
  var elems = $('.intro input').on('keypress', function() {

    if ($(this).val().trim().length > 2) {
      $(this).parent().next('label').addClass('block');
    }


    $('#intro-button').toggle(
      elems.filter(function() {
        return this.value.trim() !== "";
      }).length === elems.length
    )

  });
});
.intro {
opacity: 0;
}
.info-input {
padding: 10px 15px;
margin: 40px auto;
}
.intro:first-child {
display: block;
opacity: 1;
}
.block {
display: block;
visability: visible;
opacity: 1;
   -webkit-animation: fadein 1s ease-in;
   -moz-animation: fadein 1s ease-in;
    animation: fadein 1s ease-in;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label class="intro">What is your name?
<input id="name" type="text" class="info-input">
</label>
<label class="intro">What is your email address?
<input id="email" type="email" class="info-input">
</label>
<label class="intro">What is your title?
<input id="title" type="text" class="info-input">
</label>

Answer №1

Replace the word "animation" with "transition" in the CSS code for ".block"


    .block {
      display: block;
      visability: visible;
      opacity: 1;
      -webkit-transition: opacity 1s ease-in;
      -moz-transition: opacity 1s ease-in;
      transition: opacity 1s ease-in;
    }

Link to fiddle

Answer №2

Utilizing the animation property in CSS can achieve this effect. Here is an example:

@-webkit-keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}
@-moz-keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.your-div {
  display: none;
}
.your-div.show {
  display: block;
  -webkit-animation: fade-in 0.2s;
  -moz-animation: fade-in 0.2s;
  -o-animation: fade-in 0.2s;
  animation: fade-in 0.2s;
}

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

Creating a comprehensive dataset before initiating an AJAX request using jQuery

I've developed a system that enables an admin to assign managers to a campaign through a table. Here's how the table is structured: <tr> <td>Checkbox</td> <td>Last name, First name</td> <td>Employee Id #</td ...

Modification of window size using jQuery animations

Currently, I am working on creating a sidebar that slides in from the left side of the screen. To achieve this effect, I have set the menu element to float left with a width of 40% and a margin-left of -40%. However, when I try to reveal the sidebar by sw ...

The string obtained from input.getAttribute('value') is lacking one character

While developing e2e-tests for an angular application, I encountered a puzzling issue. When trying to retrieve the value from an using the .getAttribute('value') method, I noticed that a single character was missing. Checking the HTML properties ...

Transforming an ASPX textbox input into HTML formatted text

When I fill out the address textbox in my application for sending an inquiry email, and press enter after each line like the example below: 33A, sector -8, /*Pressed enter Key*/ Sanpada, /*Pressed enter Key*/ Navi mumbai. It should ...

Is it possible to extract elements from a single list and insert them onto various pages?

Currently, I am retrieving items from a list using an ajax call. After constructing the HTML content, I insert these items onto a page. Now, I want to extract the same items and display them on another page with a different style. Is there a method to conn ...

How to declare WinJS.xhr as a global variable in a Windows 8 Metro app

Currently, I am developing a Windows 8 Metro app and facing an issue with a hub page. The problem arises when pushing data dynamically from an XML API using two WinJs.xhr("url") calls; one for headings and the other for section datas. When merging both W ...

Prevent users from entering past dates in the date input field

In my project, I have decided to use input type date instead of datepicker. Is there a way to prevent users from selecting back dates in input type date without using datepicker? If you have any suggestions, please let me know. Thank you! ...

The results returned by the jQuery find() function vary across various pages

One interesting feature on my website is the header bar with a search function. I have implemented a function that involves resizing boxes to contain search results. On one specific page, this function works like a charm: $(".suggestionCategory").each(fu ...

Hacking the power of combining Bootstrap 3 with AngularJS to create a unique

Recently, I came across this HTML code snippet that got me thinking: <div class="input-group"> <input type="number" class="form-control" name="distance" ng-model="calculatorData.distance" placeholder="Distancia" required> ...

Saving JSON Data into my HTML document

Currently, I am in the process of learning about API's at school which means my knowledge of jQuery is quite limited. However, I have a specific task that involves making an API call and using the retrieved information. Recently, I conducted an ajax ...

Combine the PHP table with the Javascript table

I am facing a challenge where I have a table in PHP and another table in Javascript. My goal is to combine the elements of the PHP table with the elements of the Javascript table. I attempted to achieve this using the push method: <?php $tabPHP=[&apos ...

Conflicts arising from using jQuery in WordPress sites

Currently, I am utilizing the following plugin: http://wordpress.org/extend/plugins/wpmbytplayer/. However, I have encountered an issue where the background video freezes when I execute some jQuery code to animate a box in the header. Can someone shed li ...

How can I eliminate the error message "WARNING: no homepage content found in homepage.md"?

Starting my journey with KSS utilizing Keith Grant's CSS in Depth as a guide. In section 10.1.4, the author suggests: To begin, create a new markdown file named homepage.md inside the css directory. This file will serve as an introduction to the patt ...

The BorderWidth property is set to 2px, however, it is not visible on the

Struggling with adding a border to a div in my app built with react and material-ui. Here is the snippet of code I've been working with: <div className={classes.search}> ... </div> search: { ... borderWidth: '2px', borde ...

CORS request results in unsuccessful cookie setting in browsers except for Firefox where Set-Cookie header is detected; notably, Chrome does not show the header

I'm experiencing an issue with setting cookies from a NodeJS server to the client using JQuery and AJAX. Despite seeing the Set-Cookie headers in the response, the cookies are not showing up in the document.cookie string. I would greatly appreciate it ...

Trouble with parsing JSON data in JQuery getJson callback

Recently, I've encountered a strange issue with using jQuery for JSON. Even though the server is responding correctly to the request, I'm having trouble extracting the data from the JSON response. The server is ASP.MVC and is serializing using J ...

Steps for exporting a module from a JavaScript file that is linked:

When I include the main.js file in my project, the code below works properly: modules.exports = { property: value } However, if I include it in a web page like this: <!DOCTYPE html> <html> <head> <script src="main.js"& ...

Position images to the left, stacked on top of each other, with text centered on the right side of the picture

I have 5 images that I want to stack on the left side, with text displayed beside each image to the right and centered vertically. I've managed to stack the images, but the text is appearing below them instead of beside. Yes, I'm trying to creat ...

Implementing a horizontal scrollbar for an AJAX datatable

Is there a way to incorporate a horizontal scrollbar into an Ajax Datatable? I attempted to use "ScrollX" :true, however, this method did not prove successful. $(document).ready(function () { $('#myDataTable1').DataTable({ "aj ...

Is there a way to transfer the content of a div into a fresh window while retaining its original formatting

Here is a way to copy a new page: var yourDOCTYPE = "<!DOCTYPE html..."; // the doctype declaration var printPreview = window.open('about:blank', 'print_preview'); var printDocument = printPreview.document; printDocument.open(); pri ...