Skip to content

Instantly share code, notes, and snippets.

@styopdev
Created July 21, 2015 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save styopdev/1cd9625ddb6e26d0eebb to your computer and use it in GitHub Desktop.
Save styopdev/1cd9625ddb6e26d0eebb to your computer and use it in GitHub Desktop.
Background image change with fade effect
$(document).ready(function () {
var index = 1;
var coverIndex = 2;
var imagePath = "";
var coverImagePath = "";
var b = false;
setInterval(function () {
index = (index == 3 ? 1 : index + 1);
coverIndex = (coverIndex == 3 ? 1 : coverIndex + 1);
imagePath = '/images/agency/background/background-' + index + '.jpg';
coverImagePath = '/images/agency/background/background-' + coverIndex + '.jpg';
$.log(imagePath, coverImagePath);
if (b) {
b = false;
$("#fullPage").animate({"opacity": 1}, 3000, function() {
$("body").css({"background-image": 'url("' + imagePath + '")'});
});
} else {
b = true;
$("#fullPage").animate({"opacity": 0}, 3000, function(){
$("#fullPage").css({"background-image": 'url("' + coverImagePath + '")'});
});
}
}, 6000);
});
body {
position: relative;
background-image: url("/images/agency/background/background-1.jpg");
background-repeat: no-repeat;
background-size: cover;
}
#fullPage {
position: absolute;
min-width: 100%;
min-height: 100%;
top: 0;
left: 0;
background-image: url("/images/agency/background/background-2.jpg");
background-size: cover;
opacity: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment