小编use*_*123的帖子

悬停时生成随机颜色

每次我将鼠标悬停在盒子上时,我都会尝试生成随机颜色。现在,它只会生成一种随机颜色一次。

这是我的 Jquery:https://jsfiddle.net/Mulk/q0hxw0yd/#&togetherjs=uB54KHo5BN

到目前为止,这是我的代码:

$(document).ready(function(){

    var r = Math.floor(Math.random() * (255 - 0) + 0);
    var g = Math.floor(Math.random() * (255 - 0) + 0);
    var b = Math.floor(Math.random() * (255 - 0) + 0);
    var color = "rgb("+r+","+g+","+b+")"

    $("#container").hover(function(){
        $(this).css("background-color", color);
        }, function(){
        $(this).css("background-color", color);
    });

});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

2
推荐指数
1
解决办法
3935
查看次数

标签 统计

javascript ×1

jquery ×1