Seeking a method to create a dynamic background image for different sections on a one-page website, I encountered difficulty in finding suitable examples online. After browsing through various questions on Stack Overflow, I attempted to implement the following 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>
However, this code does not appear to be functioning as expected. I am unsure of what is causing the issue and how it can be resolved, especially considering that the website needs to be responsive across various resolutions.