I am facing an issue with the color changing too frequently on mouse move. I want it to be delayed and smooth, but the current code is not working as expected.
I tried adding delay()
, but it doesn't seem to be effective.
I need help understanding what I'm missing in grasping the concept
of using delay in this code.
Below is the jQuery Code-
var possible = 'ABCDEF123456';
var stringLength = 6;
$('#divcol').on('mousemove',function(){
var randomString = Array.apply(null, new Array(stringLength)).map(function () {
return possible[Math.floor(Math.random() * possible.length)];
}).join('');
var col = "#" + randomString;
$(this).delay(10000).css("background-color", col);
})
The HTML -
<div id="divcol" style="width:150px;height:150px;background-color:#c3c3c3;">
</div>
Here's a link to the Fiddle to see the code in action - http://jsfiddle.net/83mN7/
I am aiming for something similar to this -