简体   繁体   English

每个 li 元素的不同动画延迟

[英]different animation-delay for each li element

I want to set different animation-delay for each li element.我想为每个 li 元素设置不同的动画延迟。 Starting from 0 and increasing of 0.25s从 0 开始增加 0.25s

const $li = [$("div.navigation li")];
let $navLoadingTime = $("div.navigation li").css("animation-duration");

$(document).ready(function () {
    // steps loading
    const $liLength = $li[0].length;
    const $delay = $navLoadingTime.replace("s", "");

    for (var i = 0; i < $li[0].length;) {
        i++
        $li[0].css("animation-delay", $delay * i + "s")
    }
})

So far I have created something like above.到目前为止,我已经创建了类似上面的东西。 it is almost ok.几乎没问题。 However, it increases i into the maximum and sets the same maximum delay value for all of the li elements.但是,它将 i 增加到最大值并为所有 li 元素设置相同的最大延迟值。 How can I resolve it?我该如何解决?

You are doing css() on all the <li> in that collection, isolate the individual element objects with eq()您正在该集合中的所有<li>上执行 css(),使用eq()隔离各个元素对象

Try尝试

for (var i = 0; i < $li[0].length;) {            
     $li[0].eq(i).css("animation-delay", $delay * i+1 + "s");
     i++
}

Or using each()或者使用each()

$li[0].each(function(i){
   $(this).css("animation-delay", $delay * i+1 + "s");
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM