I'm currently working on adjusting the navigation bar based on the mouse position. It seems to be functioning, but I'm facing an issue with smoothing out the animation. When I stop moving the mouse to a certain point, there is a delay in updating the margin-top values which results in a jittery effect instead of a smooth transition.
function nav_animate(e) {
var mouse_y = e.pageY;
if (mouse_y < 200) {
var old_y = $("#nav-style").css('margin-top').replace('px', '');
var new_y = parseInt(old_y);
var tmp = -(mouse_y + new_y);
if (tmp > 0) {
tmp = 0;
}
$("#nav-style").css({ 'margin-top': tmp + 'px' });
}else {
$("#nav-style").css({ 'margin-top': '-101px' });
}
}
$(document).ready(function() {
$(document).on('mousemove', nav_animate);
});
Given that I may not have explained my problem clearly, here is a link to the website I am working on: here