I want to scroll the HTML page based on the mouse cursor movements, so that when moving the mouse cursor in any direction (X & Y), the scrollbars of the page move with it, scrolling the page. I'd also like the scroll to have an easing, so that it has a slight delay when moving the mouse.
I have a working prototype (without easing): https://jsfiddle.net/ssq7cda4/12/
$(document).mousemove(function (e) {
var winW = $(window).width(),
docW = $(this).width() - winW,
i = docW / winW, //increment value
x = (e.pageX - $(window).scrollLeft()) * i;
//$(window).scrollLeft(x);
//$("html, body").animate({scrollLeft:x}, 500, 'swing');
$("html, body").scrollLeft(x);
});
$(document).mousemove(function (e) {
var winW = $(window).height(),
docW = $(this).height() - winW,
i = docW / winW, //increment value
x = (e.pageY - $(window).scrollTop()) * i;
//$("html, body").animate({scrollTop:x}, 500, 'swing');
$(window).scrollTop(x);
});
The only problem is that I haven't found a way to add the easing to the scrolling. Using .animate makes the scrolling jaggy and weird. How should I animate the scrolling with easing based on mouse move?