给VTT字幕淡出效果

发布于 2025-01-24 08:03:44 字数 446 浏览 3 评论 0原文

我目前正在尝试在本地托管的页面上实现或测试新功能,该页面播放带有字幕的视频。字幕格式为VTT。

我一直在尝试找到如何实际编辑VTT本身的方法,因为我试图为字幕提供淡出的效果。

这可能不会有帮助,但是我只是尝试通过样式实施它。 。

下面是我尝试在style.css上解决的部分

.fade-in {
  animation: fadeIn 2s;
}

.fade-out {
  animation: fadeOut 3s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
     }     
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
     }     
}


I'm currently trying to implement or test a new feature on my locally hosted page which plays video with subtitles on. The subtitle format being VTT.

I've been trying to find how to actually be able to edit the VTT itself as I am trying to give a fading out effect for the subtitle.

This probably won't be helpful but I just tried implementing it via the style.css part of my project but sadly it only affects the texts of the page and I am not sure how to make it work for the texts from the VTT file itself.

Down below is the part I've tried to work out on the style.css

.fade-in {
  animation: fadeIn 2s;
}

.fade-out {
  animation: fadeOut 3s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
     }     
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
     }     
}


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2025-01-31 08:03:44

有一个

但是,并非允许所有CSS属性。
您可以更改颜色或不透明度,但无法设置动画属性。

无论如何,您可以做的是使用CSS变量设置不透明度,并且CSS变量可能会通过动画更改

:root {
  --opacity-value: 1
}

::cue {
  opacity: var(--opacity-value);
}

@keyframes flickerAnimation {
  0%   { --opacity-value: 1; }
  50%  { --opacity-value: 0; }
  100% { --opacity-value: 1; }
}

video{
 animation: flickerAnimation 1s infinite;
}

一个可以找到工作示例在这里

There is a ::cue selector to modify the subtitle text on a video.

But not all css properties are allowed.
You can change the color or opacity but you can not set the animation property.

Anyway, what you could do is to use css variable to set the opacity and the css variable could change with an animation

:root {
  --opacity-value: 1
}

::cue {
  opacity: var(--opacity-value);
}

@keyframes flickerAnimation {
  0%   { --opacity-value: 1; }
  50%  { --opacity-value: 0; }
  100% { --opacity-value: 1; }
}

video{
 animation: flickerAnimation 1s infinite;
}

An working example could be found here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文