定期 class 更换

Periodic class replacement

我正在制作 web-app,但在适当的时候更换我的当前天气图标 class 时遇到问题。 照原样,classes 是在没有清除的情况下分配的,它只是行不通。

我获取 JSON 响应并插入第一个(正确的)class

      weather.iconId = function geticonClass() {
    let prefix = data.weather[0].icon.endsWith("d")
      ? "wi-owm-day-"
      : "wi-owm-night-";
    return `${prefix}${data.weather[0].id}`;
  };

  iconElement.classList.add(weather.iconId());

然后我有 15 分钟的时间间隔进行下一次提取,之后创建并添加新的 class,但保留旧的。

我试过使用

function clearIcon() {
var element = element.(document.getElementById("current-weather-icon i")),
element.removeClass();
};

并为此设置了一个时间间隔,但它不起作用。 Here's a full JS file.

所以,我只是添加了一个简单的功能

function resetIconClass(){
$('.current-weather-icon i').removeClass()
}
$(document).ready(function(){
setInterval(resetIconClass, 905000)
});

这基本上是在插入新图标之前清除图标的 class。