Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom in effect on body background

Tags:

html

jquery

css

I want the background image of my body to zoom in on page load. The following is the code i have.

CSS:

body, html { 
    font-size: 100%; 
    padding: 0;
    margin: 0;   
    background-image: url(bg.jpg); 
    background-size: 100%;
    transition: all ease-in 5s;   

}

JQuery:

 $( document ).ready(function() {         
          $(document.body).css("background-size", "140%");
      });

I'm trying to change the background-size property of the image on page load. but this is not working. What am i doing wrong?

like image 657
Sooraj Avatar asked Jan 09 '23 03:01

Sooraj


2 Answers

All you need is:

html, body {
    background: url("http://placehold.it/200x200") top center no-repeat;
    animation: animateBg forwards 2s ease-in;
}
@keyframes animateBg{
    from { background-size: 200px; }
    to { background-size: 100%; }
}

Note: the image is just a placeholder, you can change it as well as the background-size property of the animateBg keyframe animation (and anything else you need). In case you are not aware of forwards.

Make sure to take a short while and read about CSS Animations, very convenient to be able to leverage CSS first when choosing between jQuery and CSS.

Let me know if this works for you, otherwise we can work on an improved answer that suits you better :)

like image 91
AGE Avatar answered Jan 22 '23 07:01

AGE


Hope this will resolve your query

Just a simple jquery animation play

$("body").animate({
    "background-size" : "180px"
},2000);

Try this for live demo http://jsfiddle.net/g2ef7gc4/25/

like image 26
Roshan Padole Avatar answered Jan 22 '23 06:01

Roshan Padole