My script currently generates a floored random number between 0-4 on mousemove, which is used in turn to select one of four images to display.
At the moment the images are changing too quickly, but I can't work out how to slow down the selection.
I tried to set an interval between selections in the following way, but it only introduced an initial delay after which the function behaved as normal:
var test = setInterval(Test, 250);
function Test() {
var $imgs = $('#imgs'),
$img = $('img', $imgs);
$(document).on("mousemove", function(e) {
e.preventDefault();
$img.hide().eq((Math.random()*4)|0).show();
});
};
Previously I was using another method of selecting images that I found online here, which worked very well, albeit not in a random fashion as I'd like.
$function() {
var $imgs = $('#imgs'),
$img = $('img', $imgs),
n = $img.length;
$(document).on("mousemove", function(e) {
e.preventDefault();
$img.hide().eq(((e.pageX*0.025)|0)%n).show();
I would greatly appreciate some help!
Aucun commentaire:
Enregistrer un commentaire