Looking to dynamically update the position of a div on a webpage as the user scrolls down? Check out this JavaScript script that utilizes a h2 HTML element to display the y-coordinate of the element. To see the script in action, visit the following jsFiddle: http://jsfiddle.net/adnLX/
Here is the script used to display the position:
$(document).ready(function(){
$(window).scroll(function(){
var yCoordinate = $("#bottom").position().top;
$("#title").html(yCoordinate);
});
});
In summary, the goal is to continuously update and display the position of a div as the user scrolls up and down the webpage. Currently, the script only displays the position once when initially scrolled. How can the script be modified to continuously update and display the position dynamically?