Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需要一个图片加载状态 #518

Open
afc163 opened this issue Feb 7, 2025 · 1 comment
Open

需要一个图片加载状态 #518

afc163 opened this issue Feb 7, 2025 · 1 comment

Comments

@afc163
Copy link
Member

afc163 commented Feb 7, 2025

需求动机

类似 chat.qwenlm.ai 里这个效果。

Image

提议的 API 是什么样的?

No response

Copy link

您提到需要一个类似于 chat.qwenlm.ai 中的图片加载状态效果。这个功能可以通过在图片加载时显示一个占位符或加载动画来实现,以提升用户体验。

实现建议

  1. 使用 CSS 动画: 可以使用 CSS 来创建一个简单的加载动画。在图片加载完成之前显示这个动画。

  2. 使用 JavaScript: 通过 JavaScript 监听图片的加载事件,在图片加载完成后隐藏加载动画。

  3. React 组件: 如果您使用的是 React,可以创建一个组件来封装这个功能,利用 useStateuseEffect 来管理加载状态。

示例代码

import React, { useState } from 'react';

function ImageWithLoading({ src, alt }) {
  const [loading, setLoading] = useState(true);

  return (
    <div style={{ position: 'relative', width: '100%', height: '100%' }}>
      {loading && <div className="loading-spinner">Loading...</div>}
      <img
        src={src}
        alt={alt}
        onLoad={() => setLoading(false)}
        style={{ display: loading ? 'none' : 'block' }}
      />
    </div>
  );
}

export default ImageWithLoading;

样式示例

.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* 添加您喜欢的加载动画样式 */
}

这种方法可以帮助您在图片加载时显示一个加载状态,提升用户体验。如果您有更多的具体需求或问题,请随时告诉我!

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant