To customize the content of each div, you can utilize the .scrollTop()
function in jQuery. By retrieving the value x
from .scrollTop()
, you can then modify the src
attribute of the div accordingly.
Experiment with different data sources within your "if statements" to alter your navigation image and adjust the .scrollTop()
parameter to achieve the desired outcome.
Learn more about the .scroll() event here
Find out about the .scrollTop() method here
While unable to access platforms like jsbin at work, I have successfully tested the following code snippet elsewhere. Ensure that the page actually scrolls to witness the effect.
$(function() {
$(document).scroll(function () {
var top = $(window).scrollTop();
$('#navImg').html(top);
if (top > 100) {
$('#botImg').attr('src', 'http://animalia-life.com/data_images/dog/dog1.jpg');
}
if (top < 100) {
$('#botImg').attr('src', 'http://davidfeldmanshow.com/wp-content/uploads/2014/01/dogs-wallpaper.jpg');
}
})
});
#nav {
background: black;
height: 100px;
width:100%;
}
#navImg {
height:30px;
width: 30px;
top:15px;
left:15px;
position:fixed;
background:green;
}
#bottom {
position:absolute;
top:200px;
height:1200px;
width:200px;
background:blue;
}
#botImg {
height: 100px;
width:100px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='nav'><div id='navImg'></div></div>
<div id='bottom'><img id='botImg' src='http://davidfeldmanshow.com/wp-content/uploads/2014/01/dogs-wallpaper.jpg' /></div>