Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to .animate() a background-image size

Can I .animate a background-image size with javascript/jquery?

The code where wt_r and ht_r are the screen size. Can I make that dynamic with .animate()?

$('#outer').css('background-size',wt_r+' '+ht_r);

jsfiddle- http://jsfiddle.net/m7zmzkpz/1/

like image 374
X10nD Avatar asked Nov 30 '25 07:11

X10nD


2 Answers

You can't change both height and width of a background-image.

Using .animate():

$('#outer').animate({backgroundSize: '100%'}, 800);
like image 86
Ax_6 Avatar answered Dec 01 '25 20:12

Ax_6


It is hard to answer question without more information, but you can try animate your background size with backgroundSize property? like this:

$('#outer').animate({ backgroundSize: '100%' }, 3000);

Try to use your own parameters wt_r and ht_r as backgroundSize value

Hope this helps!

like image 43
Matas Avatar answered Dec 01 '25 20:12

Matas