I am attempting to gradually increase the opacity of my div as the user scrolls, similar to this:
$(document).ready(function() {
$(document).scroll(function(e) {
changeOpacity();
});
var element = $('#element');
var elementHeight = element.outerHeight();
function changeOpacity() {
var opacityPercentage = window.scrollY / 100;
if (opacityPercentage <= 1) {
element.css('opacity', opacityPercentage);
}
}
});
This code is functional but the opacity is increasing too quickly. I have tried decreasing the opacity based on examples found online, but I cannot find a solution for increasing the opacity gradually. If my div has an initial CSS rule setting its opacity to 0, does anyone know how it should be adjusted?