dimanche 19 avril 2015

How to change background-repeat and background-size by javascript

I currently have this and it's working for me:



<script type='text/javascript'>
$(function () {
var body = $('body');
var backgrounds = [
'url(http://localhost:12448/css/images/back1.jpg) no-repeat',
'url(http://localhost:12448/css/images/back2.jpg) no-repeat'];
var current = 0;

function nextBackground() {
body.css(
'background',
backgrounds[current = ++current % backgrounds.length]);

setTimeout(nextBackground, 5000);
}
setTimeout(nextBackground, 5000);
body.css('background', backgrounds[0]);
});
</script>


I need to implement also this part of css code in to my javascript, so i can get dynamically changing background and the same css settings as it changes:



body
{
background-image: url('images/overlay.png'), url('images/bg.jpg');
background-repeat: repeat, no-repeat;
background-size: auto, 100% 100%;
}


Can anyone help me with this?


Aucun commentaire:

Enregistrer un commentaire