Created
July 21, 2015 10:50
-
-
Save styopdev/1cd9625ddb6e26d0eebb to your computer and use it in GitHub Desktop.
Background image change with fade effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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