gpt4 book ai didi

jquery - animation-duration 属性完成后如何重新计算 css 属性?

转载 作者:行者123 更新时间:2023-11-28 18:30:30 25 4
gpt4 key购买 nike

我正在尝试获得气泡上升的效果,效果非常好,看起来不错。我使用 JQuery 随机分配 css 属性,如高度、宽度或动画持续时间。但我想知道我是否可以在动画持续时间完成后重新计算一些属性。

for(var i=1; i<=7; i++)
{
var randBottom = Math.ceil(Math.random()*200);
var randWidth = Math.ceil(Math.random()*50)+20;
var randHeight = Math.ceil(Math.random()*100)+200;
var oceanWidth= $("#ocean").width();
var randLeft= Math.ceil(Math.random()*(oceanWidth-randWidth));
var randDuration = Math.ceil(Math.random()*7)+2;
var cssObj = {
'bottom' : randBottom+'px',
'height' : randHeight+'px',
'width' : randWidth+'px',
'left' : randLeft+'px',
'animation-duration': randDuration+'s',
'-moz-animation-duration': randDuration+'s',
'-webkit-animation-duration' :randDuration+'s',
'-o-animation-duration':randDuration+'s'
};
$("#bubble"+i).css(cssObj);
}

Here是我正在进行的工作的示例。

最佳答案

我认为这会为您提供您正在寻找的东西,但似乎很难使 css 关键帧持续时间和 javascript 时间同步。

您愿意将动画更改为 jQuery.animate() 吗?

for(var i=1; i<=7; i++)
{
randomizeBubble(i)
}

function randomizeBubble(i)
{
var randBottom = Math.ceil(Math.random()*200);
var randWidth = Math.ceil(Math.random()*50)+20;
var randHeight = Math.ceil(Math.random()*100)+200;
var oceanWidth= $("#ocean").width();
var randLeft= Math.ceil(Math.random()*(oceanWidth-randWidth));
var randDuration = Math.ceil(Math.random()*7)+2;
var cssObj = {
'bottom' : randBottom+'px',
'height' : randHeight+'px',
'width' : randWidth+'px',
'left' : randLeft+'px',
'animation-duration': randDuration+'s',
'-moz-animation-duration': randDuration+'s',
'-webkit-animation-duration' :randDuration+'s',
'-o-animation-duration':randDuration+'s'
};
$("#bubble"+i).css(cssObj);

setTimeout(function(){randomizeBubble(i);}, randDuration * 1000)
}

关于jquery - animation-duration 属性完成后如何重新计算 css 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14502332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com