Skip to content Skip to sidebar Skip to footer

Background Color Change On Page Load

This is my markup structure:
I wanted that on page load the color of authentication s

Solution 1:

From jquery animate()

All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used). Property values are treated as a number of pixels unless otherwise specified. The units em and % can be specified where applicable.

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%;
}

Working Fiddle

The above fiddle has a drawback that it will repeat showing the slide effect whenever you move your cursor out of the window and hover again. (which you can set using javascript/jquery).

If you want to go with jquery then check koala_dev's comment above.

Solution 2:

You can use a dynamic overlay with a slideDown() animation and then fade the form when the animation completes using 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();
});

Demo fiddle

If you want a "smoother" animation then look into jQuery UI's easing functions, you can use any of them as a parameter in slideDown() (of course for that you need include jQuery UI to your project) or you can combine the slide effect with a fade effect, example here

Solution 3:

Try this woking 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><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><script>functiondown(ids){
var speed = 10;
var ele = document.getElementById(ids);
var height = parseInt(ele.style.height || ele.offsetHeight);
height = (height + 2);
ele.style.height = height+'%';
if(height<100)
setTimeout(function(){down(ids);},speed)
else
{
    $('#form').fadeIn(); //or do whatever you wantreturn;
}
}
 </script><body><divclass="authentication"><divclass="back"id="backs"></div><divclass="form-inputs"id="form"><inputtype="text"><inputtype="submit"></div></div></body><script>down('backs');
 </script>

Post a Comment for "Background Color Change On Page Load"