以下是我所拥有的演示:http://jsfiddle.net/HgMB4/72/ 我的问题是,每当动画完成并移动到新动画时,它就会停止,然后进行下一个动画。无论如何,我可以让动画之间的停顿消失吗?我希望过渡流动,所以看起来有点像天空中漂浮的星星。请帮忙!
使用Javascript -
var main = function () {
var h = $(window).height();
var w = $(window).width();
$('#intro .box').each(function () {
var originalOffset = $(this).position(),
$this = $(this),
tLeft = 0,
tTop = 0,
tLeft = w - Math.floor(Math.random() * 900),
tTop = h - Math.floor(Math.random() * 900);
$(this).animate({
"left": tLeft,
"top": tTop
}, {
duration: 5000,
easing: 'linear'
})
$('#intro .box').each(function () {
var originalOffset = $(this).position(),
$this = $(this),
tLeft = 0,
tTop = 0,
tLeft = w - Math.floor(Math.random() * 900),
tTop = h - Math.floor(Math.random() * 900);
$(this).animate({
"left": tLeft,
"top": tTop
}, {
duration: 5000,
easing: 'linear'
})
});
});
};
$(document).ready(main);
main();
答案 0 :(得分:1)
我会使用crSpline之类的插件,然后使用
$(document).ready(function () {
// set number of animation sequences and duration range:
var sequencesNumber = 10,
minDuration = 5000,
maxDuration = 8000;
var h = $('#intro').height();
var w = $('#intro').width();
// loop through the boxes
$('#intro .box').each(function () {
var points = [];
// create random X,Y destination points for a box:
for(var i=0; i<sequencesNumber; i++){
points.push([w-Math.floor(Math.random() * 300), h-Math.floor(Math.random() * 300)]);
}
// animate box with random points:
$(this).animate({
crSpline: $.crSpline.buildSequence(points)
// calculate random transistion time for a box:
},(Math.floor(Math.random() * (maxDuration - minDuration + 1)) + minDuration));
});
});