首页 > 解决方案 > 使用基于 JSON 数据的 JavaScript 旋转风玫瑰图标

问题描述

沙盒链接。

我正在尝试旋转静态指南针图标(称为towards-0-deg/ f0b1)以反映风向。

我试过了windRose = iconRotate.rotate(data.weather.deg);,后来windElement.innerHTML = ` ${windRose.rotate(data.weather.deg)}` + `${weather.wind} km/h`;我得到了:Uncaught (in promise) ReferenceError: iconRotate is not defined

我在这里做错了什么?

标签: javascriptarraysfunctionopenweathermap

解决方案


我设法像这样修复它:

      weather.rose = function(){
    $(".wi-wind").addClass("from-" + windDirection + "-deg")
    setTimeout(function (){
      $("#roseIcon").removeClass();
      setTimeout(function () { 
      $("#roseIcon").addClass(`wi` +` `+ `wi-wind` +` `+ `from-` + windDirection + `-deg`)}, 1000)
    },920000)
  };

推荐阅读