跳到正文
Skillpedia
网站与界面(前端)7.2k · #13413

cobejs

它能做什么

这个技能指导 AI 智能体使用 cobe 库在网站中加入一个紧凑的三维地球。适合需要带标记的装饰性地球的首屏或关于页面,而无需沉重的三维工具包。

适用场景

  • ✓当首屏或关于页面需要一个带位置标记的旋转地球时。
  • ✓当你只想要一个小型地球,而不是完整的三维工具包时。
  • ✓当地球仅用于装饰,但仍需响应交互时。

技能链接

https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/cobejs/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/cobejs/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我在关于页面加一个小型旋转地球,上面标出我们三个城市的办公室位置。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会设置画布,根据屏幕调整大小,并用标记的坐标和颜色创建地球。它还会处理尺寸变化,在手机上限制像素密度,并可以暂停或移除地球。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

cobe.js — Lightweight WebGL Globe Skill

When to use

  • A “spinning globe” / location markers in hero or about pages
  • You want a small, focused globe lib (not full three.js)
  • Decorative + interactive (markers, rotation) with minimal setup

Key APIs/patterns

  • Core:
    • import createGlobe from "cobe"
    • const globe = createGlobe(canvas, { ...options, onRender(state) { ... } })
  • Important options (common):
    • devicePixelRatio, width, height
    • phi, theta (rotation angles)
    • scale, dark, diffuse
    • baseColor, markerColor, glowColor
    • markers: [{ location: [lat, lon], size, color? }]
  • Lifecycle:
    • globe.toggle() pauses RAF
    • globe.destroy() removes instance

Common pitfalls

  • Canvas sizing mismatch
    • Set CSS size AND set canvas width/height scaled for DPR.
  • Not updating on resize
    • Recompute width/height and recreate or update params.
  • Too high DPR on mobile
    • Clamp DPR to 1–2.

Quick recipe: responsive globe with markers

import createGlobe from "cobe";

const canvas = document.getElementById("cobe");
let phi = 0;

function setup() {
  const rect = canvas.getBoundingClientRect();
  const dpr = Math.min(window.devicePixelRatio, 2);
  canvas.width = Math.round(rect.width * dpr);
  canvas.height = Math.round(rect.height * dpr);

  const globe = createGlobe(canvas, {
    devicePixelRatio: dpr,
    width: canvas.width,
    height: canvas.height,
    phi: 0,
    theta: 0.2,
    dark: 0,
    diffuse: 1.2,
    scale: 1,
    mapSamples: 16000,
    mapBrightness: 6,
    baseColor: [0.2, 0.2, 0.25],
    glowColor: [1, 1, 1],
    markerColor: [0.8, 0.5, 1],
    markers: [{ location: [1.3521, 103.8198], size: 0.08 }],
    onRender: (state) => {
      state.phi = phi;
      phi += 0.01;
    },
  });

  return globe;
}

let globe = setup();
window.addEventListener("resize", () => {
  globe.destroy();
  globe = setup();
});

What to ask the user

  • Globe size and placement (hero, section, card)?
  • Marker locations + colors (brand-aligned)?
  • Interaction needs (drag to rotate vs. ambient spin)?
常见问题

它需要 React 吗?

不需要,但该技能包含在 React 和 Next.js 中使用的说明。

标记是什么?

按纬度和经度放置的点,每个点都可以设置大小,并可选颜色。

为什么画布尺寸很重要?

该技能提醒,画布尺寸必须与屏幕的像素比例匹配,因此需要同时设置屏幕显示尺寸和绘制尺寸。

详情

作者的原始描述

Use when adding a lightweight interactive globe with cobe (canvas setup, markers, interaction, performance, integration with React/Next.js).

repo: MengTo/Skills

热度

GitHub 星标
7.2k
排名
#13413
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能