這裏是我的代碼新的隨機數的jQuery
(function ($) {
$.fn.snow2 = function (options) {
var $flake = $('<a style="text-decoration: none;" href="/flake"><div id="flake" /></a>').css({
'position': 'absolute',
'top': '-50px',
'z-index': '100'
}).html('❄'),
documentHeight = $(document).height(),
documentWidth = $(document).width(),
defaults = {
minSize: 30,
maxSize: 50,
newOn: Math.floor(Math.random() * 14000) + 7000,
flakeColor: "#CE1126"
},
options = $.extend({}, defaults, options);
var interval = setInterval(function() {
var startPositionLeft = Math.random() * documentWidth - 100,
startOpacity = 0.5 + Math.random(),
sizeFlake = options.minSize + Math.random() * options.maxSize,
endPositionTop = documentHeight - 40,
endPositionLeft = startPositionLeft - 100 + Math.random() * 200,
durationFall = documentHeight * 10 + Math.random() * 5000;
$flake
.clone()
.appendTo('body')
.css({
left: startPositionLeft,
opacity: startOpacity,
'font-size': sizeFlake,
color: options.flakeColor
})
.animate({
top: endPositionTop,
left: endPositionLeft,
opacity: 0.2
},
durationFall,
'linear',
function() {
$(this).remove()
}
);
}, options.newOn);
};
})(jQuery);
我試圖讓它在像7000個14000毫秒隨機間隔吐出了雪花,問題是當我調用函數它得到一個隨機數在7000到14000之間,並且一次又一次地使用相同的值。所以說它返回12806,它會每12806毫秒吐出一片雪花。我每次都需要一個新號碼。我將如何去完成這件事?我從一些不同的代碼中分解了這些代碼,並且對JavaScript或jQuery不太熟悉。任何幫助表示讚賞。
我愛雪!多麼有趣的想法。 – andi