Magnifying effect on the background of the body
I want my body's background image to grow on page load. Below 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 am trying to change a property of an background-size
image on page load. but it doesn't work. What am I doing wrong?
source to share
All you need is a jsFiddle
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 keyframe animation animateBg (and whatever else you need). If you donโt know the transitions .
Don't forget to take a short time and read about CSS Animations , it comes in handy to be able to use CSS first when choosing between jQuery and CSS.
Let me know if this works for you, otherwise we can improve on the improved answer that works for you :)
source to share
Hope this resolves your request
Simple animation playback jquery
$("body").animate({
"background-size" : "180px"
},2000);
Try this for a live demo http://jsfiddle.net/g2ef7gc4/25/
source to share
try
$("body").animate({
"background-size", "140%"
},20000, function() { alert(); });
see example background zoom effect
source to share
@sooraj just sets the height and width as a demo
$( document ).ready(function() {
$(document.body).css("background-size", "140%");
});
body, html {
font-size: 100%;
padding: 0;
margin: 0;
background-image: url(//images.visitcanberra.com.au/images/canberra_hero_image.jpg);
background-size: 100%;
transition: all ease-in 5s;
height:500px;
width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body></body>
source to share