惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
博客园_首页
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
D
Docker
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
量子位
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Cloudbric
Cloudbric
博客园 - 司徒正美
H
Help Net Security
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LangChain Blog
Latest news
Latest news
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
博客园 - Franky
S
Security Affairs
W
WeLiveSecurity
F
Full Disclosure
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
美团技术团队
PCI Perspectives
PCI Perspectives
C
Check Point Blog
Spread Privacy
Spread Privacy

Hyde Blog

Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog 关于我 关于我 Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog
Hyde Blog
Hyde · 2025-10-05 · via Hyde Blog

顶部复制提示 ​

新建沟子 ​

  • docs\.vitepress\theme\composables\下创建useCopyEvent.ts

ts

// 搭配modal.scss使用,这是横幅提示地基文件
export function useCopyEvent(): void {
  document.addEventListener("copy", () => {
    const selection = window.getSelection();
    if (!selection || selection.toString().trim() === "") {
      showEmptyCopyBanner();
    } else {
      showSlideBanner();
    }
  });
}

export function triggerCopyEvent(): void {
  showSlideBanner();
}

function showSlideBanner(): void {
  const banner = document.createElement("div");
  banner.className = "slide-banner";
  banner.innerHTML = `
      <div class="slide-content">
        <!-- 这里是复制后,提示的文本内容-->
        <h1>✨️你拷贝了哦!被我发现呢,一定要标注本文来源哦!</h1>
      </div>
      <div class="slide-block"></div>
    `;

  document.body.appendChild(banner);

  // 出现动画~
  setTimeout(() => {
    banner.classList.add("show");
  }, 10);

  setTimeout(() => {
    const slideBlock = banner.querySelector(".slide-block") as HTMLElement;
    slideBlock.style.width = "100%";
  }, 10);

  setTimeout(() => {
    banner.classList.add("hide");
  }, 3000); // 调整横幅存在时间,这里是毫秒单位哦~
}

function showEmptyCopyBanner(): void {
  const banner = document.createElement("div");
  banner.className = "slide-banner";
  banner.innerHTML = `
      <div class="slide-content">
        <h1>您没有选中任何复制内容哦~</h1>
      </div>
      <div class="slide-block"></div>
    `;

  document.body.appendChild(banner);

  // 出现动画~
  setTimeout(() => {
    banner.classList.add("show");
  }, 10);

  setTimeout(() => {
    const slideBlock = banner.querySelector(".slide-block") as HTMLElement;
    slideBlock.style.width = "100%";
  }, 10);

  setTimeout(() => {
    banner.classList.add("hide");
  }, 3000); // 空复制提示显示时间稍短
}

样式文件 ​

  • docs\.vitepress\theme\styles\下创建CopySjHfTs.scss

scss

// 搭配useCopyEvent.ts使用,这是横幅提示样式文件

.slide-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 9999;
  background: var(--vp-c-brand-1); // 背景的颜色配置
  text-align: center;
  overflow: hidden;
  transform: translateY(-100%);
  transition:
    transform 1s ease,
    opacity 1s ease;

  .slide-content {
    padding: 20px;
    font-size: 1rem;
    backdrop-filter: blur(5px); // 预设值)当设置为半透明背景的时候,会有高斯模糊玻璃质感
    position: relative;
    z-index: 2;

    h1 {
      margin: 0;
      font-size: 1.2rem;
      color: rgb(255, 255, 255); // 文字的颜色配置
      font-weight: bold;
    }
  }

  .slide-block {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background-color: #c7c7c72f; // 滑动块的颜色配置
    transition: width 2s ease-in-out; // 动画持续时间的配置
    // animation: remove-corner 2s ease-in-out forwards; // 逐渐圆角的动画配置,建议与  transition 保持一直呢~😏
    // border-top-right-radius: 25px; // 圆角效果,注释/删除,取消圆角,需要同时删除下面的代码🔽
    // border-bottom-right-radius: 25px; // 圆角效果,注释/删除,取消圆角,需要同时删除上面的代码🔼
    z-index: 1;
  }

  &.show {
    transform: translateY(0);
  }

  &.hide {
    transform: translateY(-100%);
    opacity: 0;

    .slide-block {
      width: 100%;
      border-radius: 0;
    }
  }
}

@keyframes remove-corner {
  0% {
    border-top-right-radius: 25px;
    border-bottom-right-radius: 25px;
  }
  80% {
    border-top-right-radius: 15px;
    border-bottom-right-radius: 15px;
  }
  100% {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
}

@media (max-width: 768px) {
  .slide-content {
    font-size: 0.9rem;
    padding: 15px;
  }
}

注册钩子 ​

  • docs\.vitepress\theme\index.ts中注册钩子

ts

// 引入复制事件(复制后弹窗提示)
import { useCopyEvent } from "./composables/useCopyEvent.ts"; 

export default {
  extends: Teek,

  Layout: defineComponent({
    setup() {
      if (typeof window !== "undefined") {
        // 监听复制事件
        useCopyEvent();
      }
    },
  }),
};