You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

xaringan演示文稿如何设置整场演讲的总倒计时?

xaringan演示总时长限制配置方法

xaringan原生的nature配置项暂不支持直接设置整场演示的总时长限制,可通过以下两种常用方案实现:

  • 方案一:使用countdown扩展包(专为xaringan设计的计时工具)
    1. 先安装对应包:install.packages("countdown")
    2. 在文档的setup代码块中添加如下代码即可实现15分钟全局倒计时,计时组件默认会固定在页面角落,不影响正常幻灯片播放:
    library(countdown)
    # 可自定义时长、显示位置、结束提示音等参数
    countdown_fullscreen(
      minutes = 15, 
      seconds = 0, 
      position = "top-right"
    )
    
  • 方案二:自定义JS代码实现(无需额外安装包)
    直接在Rmd文档任意位置插入如下JS代码即可,可根据需求自行修改显示样式、提示逻辑:
    <script>
    // 总时长设置为15分钟,可自行修改数值
    const totalDuration = 15 * 60 * 1000;
    const presentationStartTime = Date.now();
    
    function refreshTotalTimer() {
      const timeUsed = Date.now() - presentationStartTime;
      const timeLeft = totalDuration - timeUsed;
      const timerElement = document.getElementById('global-timer');
      if (timeLeft <= 0) {
        timerElement.textContent = "已超出总时长!";
        timerElement.style.color = "#dc2626";
        return;
      }
      const remainMinutes = Math.floor(timeLeft / 60000);
      const remainSeconds = Math.floor((timeLeft % 60000) / 1000);
      timerElement.textContent = `总剩余:${remainMinutes}分${remainSeconds}秒`;
    }
    
    // 插入计时显示容器
    const globalTimer = document.createElement('div');
    globalTimer.id = 'global-timer';
    globalTimer.style.cssText = `
      position: fixed;
      top: 12px;
      right: 12px;
      z-index: 9999;
      background: #fff;
      padding: 4px 12px;
      border-radius: 6px;
      font-size: 14px;
      font-weight: 500;
    `;
    document.body.appendChild(globalTimer);
    
    // 每秒刷新计时
    setInterval(refreshTotalTimer, 1000);
    </script>
    

两种方案都可以和你原有单页幻灯片的countdown配置同时使用,互不冲突。

内容的提问来源于stack exchange,提问作者RxT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 08:36:03