Tôi đã thấy nhiều nơi sử dụng Math.floor()
và Math.random()
Giải thích Math.floor (Math.random())
như dưới đây
$('a.random-color').hover(function() { //mouseover
var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
$(this).animate({
'color': col,
'paddingLeft': '20px'
},1000);
},function() { //mouseout
$(this).animate({
'color': original,
'paddingLeft': '0'
},500);
});
});
Tại sao sử dụng Math.floor()
và Math.random()
?