我想在活动幻灯片中添加“is-active”类,并在出来的幻灯片中添加“is-out”类

问题描述

我有以下 HTML 文档,它是幻灯片

bytes

与以下代码相关的javascript代码如下:

sha256

我想要做的是在即将出现的幻灯片添加“is-out”类。

这意味着每个包含“is-active”的类都会更改为“is-out”,而“is-out”类将添加到下一张幻灯片中。

另一件事:is-out 类应该持续 1 秒并且应该被删除

解决方法

您可以使用 querySelector 查找具有 .isActive 类的节点。然后你可以从它发生的节点中删除它。

它看起来像这样:

file = open('times.txt','r')  # wrong = 4
print(file.read())  # wrong = 4
wrong = list(file.read())  # there is a problem,when is str not problem but if int => wrong = 0
print(wrong)  # wrong = 0

setInterval 方法将解决您的计时问题。它将在您确定的设定时间后运行一个函数。 Read more here.

您可以像上面那样设置 i = 0,而不是运行 for 循环。然后在你的 setInterval 函数中,有:

let isActive = document.querySelector('.is-active')
if (isActive !== null){
isActive.classList.remove('is-active')

所有这些一起将 1) 搜索具有 'is-active' 类的任何节点 2) 将其删除,3) 将 'is-active' 类添加到列表中索引值等于 i 的节点中那个间隔。