I need list of all class name of Font-Awesome

前端 未结 18 3041
傲寒
傲寒 2020-12-12 13:44

I build app that will present a lot of icons so I need list of all Font-Awesome class name like [\"fa-dropbox\",\"fa-rocket\",\"fa-globe\", ....] so on is ther

18条回答
  •  Happy的楠姐
    2020-12-12 14:27

    how to get Font Awesome Icons in a JSON object grouped by categories

    I made this to use with the excellent jQuery fontIconPicker

    Done with with FA Version 5.0.6

    JSON result is available at https://gist.github.com/migliori/60154172ba0eea70e3c0dd4c3b5d82d0 for lazy people.

    1. Navigate to https://fontawesome.com/icons?d=gallery&m=free

    2. Paste this code in your browser console to grab the available categories and their icons. Wait about 2 minutes and it will return them into a JSON Object

      if(typeof endList == 'undefined') {
          var endList         = new Object();
          var catList         = document.getElementsByClassName('fa-ul')[2];
          var catListElements = catList.getElementsByTagName('li');
          var catListLength   = catListElements.length;
          console.log(catListLength);
          var i;
      
          var getIcons = function(el) {
              var classes = new Array();
              var name    = el.innerText;
              console.log(name);
              var icons   = document.getElementById('results-icons').getElementsByTagName('svg');
              for (var icon of icons) {
                var clazz = icon.getAttribute('data-prefix') + ' fa-' + icon.getAttribute('data-icon');
                classes.push(clazz);
              }
              console.log(classes);
              console.log('-----');
              endList[name] = classes;
      
              if(i + 1 < catListLength) {
                  el.getElementsByClassName('relative')[0].click();
                  i++;
                  setTimeout(getCategory, 3000);
              } else {
                  console.log(JSON.stringify(endList));
              }
      
              return;
          }
      
          var getCategory = function() {
              var el = catListElements[i];
              el.getElementsByClassName('relative')[0].click();
              setTimeout(function() {
                  getIcons(el);
              }, 3000);
          }
      }
      i = 0;
      getCategory();
      

提交回复
热议问题