Page load triggers background color shift

Here is the structure of my markup:

<div class="authentication">
  <div class="form-inputs"></div>
</div>

My goal is to have the color of the authentication section slide down from top to bottom when the page loads. Initially, the color is white and I want blue to fill in from the top (similar to how the header color fills the body).

I attempted this using the following code:

<script>
  jQuery(document).ready(function($) {
    $('.authentication').animate({backgroundColor: '#4BC5DA'}, 3000);
  });
</script>

However, it ends up having a fade in effect.

After the color changes, I would like the "form-inputs" to fade in as well. I understand that I need to chain these actions together but I'm having trouble figuring out the exact implementation.

Answer №1

Referenced from jquery animate()

When using the animate() function in jQuery, it's important to note that all animated properties should be animated to a single numeric value. Additionally, most properties that are non-numeric cannot be animated using basic jQuery functionality. For example, properties like width, height, or left can be animated, but background-color cannot be unless the jQuery.Color() plugin is utilized. Property values are considered as a number of pixels by default, unless specified otherwise. Units like em and % can be used where appropriate.

Updated (Using css)

.authentication {
    width: 100%;
}
body:hover .authentication{
    height: 100%;
    background-color: #4BC5DA;
    -webkit-transition: background-color 3s ease, height 3s ease;
    -moz-transition: background-color 3s ease, height 3s ease;
    -o-transition: background-color 3s ease, height 3s ease;
    -ms-transition: background-color 3s ease, height 3s ease;
    transition: background-color 3s ease, height 3s ease;
}
body, html {
    width: 100%;
    height: 100%;
}

See the Working Fiddle Here

The fiddle mentioned above may continuously repeat the slide effect when the cursor goes out of the window and hovers again; to address this, you can implement a solution using javascript or jquery.

If you prefer using jquery, you can refer to koala_dev's comment in this link.

Answer №2

To create a dynamic overlay, try using the slideDown() animation. After the animation is complete, you can fade the form by utilizing the callback argument:

$blue = $('<div>').css({
    background: 'blue',
    position: 'absolute',
    width: '100%',
    height: '100%',
    top: '0',
    display: 'none'
}).appendTo('.authentication').slideDown('slow', function(){
    $('.form-inputs').fadeIn();
});

Check out the demo on JSFiddle

If you prefer a smoother animation, explore jQuery UI's easing functions. You can incorporate any of these functions as a parameter in slideDown(). Alternatively, you can combine the slide effect with a fade effect for a different visual effect. See an example here.

Answer №3

Check out this working demo on Fiddle: http://jsfiddle.net/Z3Ts7/5/

<style>
.authentication{position:absolute;width:400px;height:300px;border:1px #c0c0c0 solid;overflow:hidden;}
.back{position:absolute;z-index:0;height:0%;width:100%;background-color:#53a2fa;}
#form{position:absolute;z-index:1;width:100%;height:100%;display:none;}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function expandHeight(ids){
var speed = 10;
var element = document.getElementById(ids);
var height = parseInt(element.style.height || element.offsetHeight);
height = (height + 2);
element.style.height = height+'%';
if(height<100)
setTimeout(function(){expandHeight(ids);},speed)
else
{
    $('#form').fadeIn(); //or implement your desired functionality
    return;
}
}
 </script>
<body>
 <div class="authentication">
    <div class="back" id="backs"></div>
    <div class="form-inputs" id="form">
    <input type="text">
    <input type="submit">
    </div>
</div>
</body>
<script>
expandHeight('backs');
 </script>

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

Having trouble getting a value from a textbox to PHP using jQuery - can anyone lend a hand?

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5b1.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script> <input type="text" id= ...

Advantages of choosing between the <NextLink/> and the <Button href="/somePage"/> components in the powerful Mui React UI libraries

Currently engaged in a project, I am wondering if there exists a substantial disparity in the utilization of these two components. Prior to this change, the return button was implemented as follows: <NextLink href="/settings" ...

What could be the reason for the bottom edge of my central diagonal image having a darker border?

I can't figure out why the border on the bottom edge of my image is darker. You can check out the demo here. To get a closer look at the issue, you can open a software like GIMP and zoom in on the following image to see the difference in values: http ...

access denied on image links

While developing a web app with Angular5, I encountered an issue regarding retrieving image URLs from the 4chan API. Each post in my database contains an image URL, however, when I try to access it through my app, I receive a 403 forbidden error in the con ...

How come my gifs appear tiny even though I've adjusted their width to 32% each?

I am trying to display three gifs in a row, each taking up one-third of the width of the page. However, when I preview the page, the gifs appear tiny. I have set the divs to 32% each and the gifs should fill 100% of their respective div. Here is the code s ...

Page redirection to a different URL after a successful AJAX call

I need assistance in registering a new user using an HTTP POST method with Ajax and Spring backend. I have successfully created a function to send JSON data to the controller and persist it in the database. However, I am facing an issue where after process ...

Can a partially see-through front color be placed on top of an image?

My goal is to add a foreground color with opacity over some images within a div, allowing the image to still be visible. I've come across solutions on S.O., like this one, but they don't quite achieve what I'm looking for. Below is my HTML ...

Set up an event listener for when geolocation permission is approved

My Setup: I've written some basic code snippet below: const onSuccess = () => { console.log('success'); } const onError = () => { console.log('error'); } navigator.geolocation.getCurrentPosition(onSuccess, onError) ...

Reactjs and Isotope offer the ability to expand and collapse on click. In this unique feature, only one item can be expanded at

Currently, I am working on refining an isotope application where each item expands upon clicking it and collapses when another item is clicked. However, the issue I am facing is that multiple cells can be opened simultaneously. I am looking for the most ef ...

I'm having difficulty grasping how this CSS is being used

There's something strange about the way this CSS is being used, and I can't quite wrap my head around it. .tablecontainer table { ... } I'm familiar with table.tablecontainer, which indicates that the class attribute is equal to "table ...

Using Three.js to create a blurred SVG texture from a canvas

I am attempting to apply an SVG as a texture over a model with UV mapping, but it appears very blurry. I'm using the texture from a 2D canvas, which looks fine on its own, but once applied to the model, it doesn't look good at all. Any suggestion ...

How come the h2::after element is positioned directly beneath the main h2 element, and with a margin-bottom?

I'm puzzled as to why the margin-bottom property in the main h2 element isn't affecting its "::after" element. Both are defined as block elements, so one margin should provide enough space between them. Even though the "h2::after" element has 0 m ...

Setting line height as a pixel value does not yield the desired result

$(element).css(options.css).attr(options.attr).addClass(options.class) //ensure line-height is correctly assigned if($(element).is('p') && _.isString(options.css['line-height'])){ console.log('line-height assigned: &apos ...

Utilizing jQuery Mobile to tap into smartphone functionalities like camera and calling capabilities

Can mobile features like the camera and sensors be accessed from an HTML page created with jQuery Mobile? In simpler terms, is it feasible to utilize mobile features using jQuery Mobile? It's clear that I will be accessing this page on a mobile phon ...

Tips for successfully passing an array containing an object to an AJAX action

I am facing an issue with passing an object in AJAX that has a list of properties to my action. The problem is that the list always ends up being null. How can I resolve this? Below is the code snippet: Class Definitions : public class SaveProduct { ...

Keep JS Accordion open when links are clicked

Utilizing PHP, I am fetching items from a database and creating an HTML table to display each item. Adjacent to the HTML table, there is a side menu with an accordion function implemented in JavaScript. Within each accordion section, there are links for ...

Using inline styles can cause Content Security Policy (CSP) violations in applications

I have been diligently working on an application for quite some time using create-react-app. Recently, I decided to update to the latest version of React only to find out that a new Content Security Policy (CSP) has been implemented. To my dismay, upon tr ...

"Is it possible to conditionally render a component depending on the state in

One of the challenges I'm facing is customizing a filter icon from MaterialUI. My goal is to change its color to black when a checkmark is checked, and adjust its position accordingly. Additionally, when a box is checked, it should fill in setFilters. ...

Customizing PHP output in Ajax and JSON: A step-by-step guide

I have a field in my MySQL table that stores addresses like: I can retrieve this field from MySQL using two PHP files (Ajax-jQuery Autocomplete Process) 1: GetAuto1.php <?php include("configPDO.php"); $likeString = '%' . $_GET[' ...

Making a XMLHttpRequest/ajax request to set the Content-Type header

In my attempts, I have tested the following methods individually: Please note: The variable "url" contains an HTTPS URL and "jsonString" contains a valid JSON string. var request = new XMLHttpRequest(); try{ request.open("POST", url); request.set ...