0

マウスの移動で色が頻繁に変化しますが、色を遅らせて滑らかにしたいのですが、コードが正しく機能していません。

このために導入delay()しましたが、機能していないようです。

conceptコードで遅延を使用するために不足しているものを教えてください。

jQuery コード -

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);
    })

HTML -

<div id="divcol" style="width:150px;height:150px;background-color:#c3c3c3;">
</div>

フィドル - http://jsfiddle.net/83mN7/

私が達成しようとしているこのようなもの - http://www.aino.com/

4

3 に答える 3

3

を使用しjQuery animationてこれを実現できます。

$(this).animate({ backgroundColor: col }, 1500);
于 2013-08-22T13:23:04.027 に答える
1

最善の解決策ではありませんが、機能します:

http://jsfiddle.net/83mN7/20/

var possible = 'ABCDEF123456';
var stringLength = 6;
var count = 0;
$('#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;
    count = count + 1;
    if (count > 30) {
        $(this).css("background-color", col);
        count = 0;
    }

});
于 2013-08-22T13:30:43.467 に答える