Stay Hungry,Stay Foolish!

async - 异步流程控制神器 - help animating webpage

async

https://www.npmjs.com/package/async

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install async, it can also be used directly in the browser. A ESM version is included in the main async package that should automatically be used with compatible bundlers such as Webpack and Rollup.

A pure ESM version of Async is available as async-es.

For Documentation, visit https://caolan.github.io/async/

For Async v1.5.x documentation, go HERE

 

API

https://github.com/caolan/async/blob/v1.5.2/README.md#waterfall

Control Flow

 

动画

https://github.com/fanqingsong/async_animation

index.js

复制代码
import './css/style.css';
import './sass/index.scss';

var async = require("async");

window.onload = () => {
    let salutions = document.querySelectorAll("#salutions>div");
    for(let one of salutions){
        one.style.display = "none";
    }

    async.waterfall([
        function(callback) {
            salutions[0].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[1].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[2].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[3].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            callback(null);
        }
    ], function (err, result) {
        // result now equals 'done'
    });
};
复制代码

 

html

复制代码
    <div class="c-Sticky">
        <div class="c-Sticky-bd">
            <h1 style="text-align: center;">Async Show</h1>

            <div id="salutions" style="font-size: xx-large; color:blue;  display: flex; justify-content:center;">
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: steelblue"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: antiquewhite"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: azure"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: beige"></div>
            </div>

        </div>
    </div>
复制代码

 

效果

 显示从左到右每个一秒显示一个方块字。

 

posted @   lightsong  阅读(970)  评论(0编辑  收藏  举报
编辑推荐:
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
千山鸟飞绝,万径人踪灭
点击右上角即可分享
微信分享提示