I tried to find a way to make a changeable background image for a one pager. Basically when the user scrolls down to the "About us" section there should be a specific background image for that section, one for "Contact" and so on. It's either that I can't find it or there are not enough examples on the internet on this topic. After reading some questions on Stack Overflow I came up with this code:
<style>
body {
background-image:url('http://7-themes.com/data_images/out/39/6901356-free-background-images.jpg');
}
</style>
<script type="text/javascript">
$(window).scroll(function() {
var image_url = 'http://7-themes.com/data_images/out/39/6901356-free-background-images.jpg';
if ($(window).scrollTop() > 800) {
image_url = 'http://www.designbolts.com/wp-content/uploads/2014/03/Yellow-blur-background1.jpg';
}
$(body).css('background-image', image_url);
});
</script>
It doesn't seem to work and I don't understand why. The website is responsive so the solution should include some explanation at least for making it work on different resolutions.
$('body').css('background-image', 'url(' + image_url + ')');. Notice the quotes aroundbodyand theurl()around yourimage_url$(body).css('background-image', image_url);part of my script with it. Still wouldn't work.