Skycons, cant display the same icon twice?

后端 未结 1 1187
感情败类
感情败类 2020-12-17 01:08

I\'ve hooked up the JavaScript plugin \"Skycons\" to Yahoo weather RSS feed. The problem I am having is that multiple days may have the same weather forecast and because the

相关标签:
1条回答
  • 2020-12-17 01:27

    You should use the version that works with element references instead of id

    (And change the html to use classes instead of ids)

    for(i = list.length; i--; ) {
        var weatherType = list[i],
            elements = document.getElementsByClassName( weatherType );
        for (e = elements.length; e--;){
            icons.set( elements[e], weatherType );
        }
    }
    

    and change your html to

       <li class="col-md-3 col-sm-3 col-xs-3"><strong>Saturday</strong>
             <canvas class="snow" width="50" height="50"></canvas>
             <span>19&deg;</span>
       </li>
       <li class="col-md-3 col-sm-3 col-xs-3"><strong>Sunday</strong>
             <canvas class="rain" width="50" height="50"></canvas>
             <span>19&deg;</span>
       </li>
       <li class="col-md-3 col-sm-3 col-xs-3"><strong>Monday</strong>
             <canvas class="sleet" width="50" height="50"></canvas>
             <span>19&deg;</span>
       </li>
       <li class="col-md-3 col-sm-3 col-xs-3"><strong>Wednesday</strong>
             <canvas class="snow" width="50" height="50"></canvas>
             <span>19&deg;</span>
       </li>
    

    If you need to support IE8 and older you need to use this polyfill for the getElementsByClassName function: Polyfill for getElementsByClassName for particular uses

    0 讨论(0)
提交回复
热议问题