I have a page with a gradient applied on page load via CSS and would like to animate the page alternating the gradient colors and degree (linear-gradient - 4 different colors all degrade to white) on mouse move. If I use only 2 colors it works fine. But I want to get a random color from an array on mouse move but it flickers. Any solution for that?
Here's my Fiddle
var colorArr = ['#dfa7ca', '#f7c2b3', '#bae0f1', '#a6d6cb'];
var grFrom = colorArr[Math.floor(Math.random()*colorArr.length)];
var grTo = '#FFFFFF';
$("body").mousemove(function( e ) {
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
var grFrom = colorArr[Math.floor(Math.random()*colorArr.length)];//get a new random color
var xy = (x + y) / 8;
var w = $(this).width(),
pct = 360*(+e.pageX)/w,
bg = "linear-gradient(" + xy + "deg,"+grFrom+","+grTo+")";
$("body").css("background-image", bg);
});