Как сделать, если я хочу сделать рандомизированные цвета, но с парой наборов, которую я сделал с помощью метода onload при рандомизации occcur? - PullRequest
0 голосов
/ 11 декабря 2019

Хы, я хочу делать разные цвета каждый раз, когда страница вызывается или открывается, и с набором пар, которые я сделал за столом, с различной персонализацией цвета строк. Как мне сделать это правдой ??? Эта строка кода CSS , которую я пытаюсь достичь для достижения некоторых целей:


Я пытаюсь использовать метод Math , чтобы получить случайные цвета, но я 'Я застрял с этим. потому что это не будет персонализация пары цветов. Посмотрите код, который я сделал с javascript, ниже:


---------------------------------------------------------- GS -----------------------------------------------------------------


function randomColor(customColorsArray, takenColorsArray) {
 var text = "",
     colors = ["orange", "yellow", "red", "maroon"];

   if (customColorsArray && takenColorsArray) {
      var text = "["+colors+"]";
   }
     else if (!customColorsArray && !takenColorsArray) {
      text += colors[Math.floor(Math.random() * colors.length)];
   }
     else {
      text += customColorsArray[Math.floor(Math.random() * customColorsArray.length)];
  };

   return text;
}


function personalRandomColor(e, customColor1, customColor2, customColor3, customColor4) {
 var text = "";

   if (!customColor1) {
      if (e == "orange") {text += "white";}
      else if (e == "red") {text += "blue";}
      else if (e == "yellow") {text += "magenta";}
      else if (e == "maroon") {text += "almond";};

   } else {
       if (e == "orange") {text += customColor1;}
       else if (e == "yellow") {text += customColor2;}
       else if (e == "red") {text += customColor3;}
       else if (e == "maroon") {text += customColor4;};
   };

  return text;
}


function showTable() {
  var s = SpreadsheetApp,
      ss = s.getActiveSpreadsheet(),
      sss = ss.getSheets(),
      Html = HtmlService.createHtmlOutput(result)
            .setSandboxMode(HtmlService.SandboxMode.IFRAME)
            .setWidth(545)
            .setHeight(500),
      customColorsArrays = randomColor('passingClass', 'takenColor'),
      randomFirstColor = 'yellow',
      skipFirstColor = customColorsArrays.replace('yellow,', ''),
      randomSecondColor = randomColor(toString(skipFirstColors)),
      result = "<head>
                   <style type='text/css'>
                      .gridview {
                        display: inline-block;
                        border-collapse: collapse;
                        margin: 0px 4px 4px 0;
                        box-shadow: 3px 3px 4px #bbb;
                      }

                      .gridview, .gridview td {
                        margin: 0;
                        border:  1px solid #cccccc;
                      }

                      .gridview tr:nth-child(even) {
                        background-color: "+randomFirstColor+";
                      }

                      .gridview tr:nth-child(odd) {
                        background-color: "+randomSecondColor+";
                      }

                      .gridview td {
                        font-weight: normal;
                        text-align: left;
                        vertical-align: middle;
                      }

                      .gridview td {
                        padding: 4px 10px 5px 9px;
                      }
                   </style>
               </head>
            <table border=1 class='gridview'>";

                for (var i = 0; i < sss.length; i++) {
                   result += "<tr>";
                    result += "<td>" + sss[i].getName() + "</td>";
                   result += "</tr>";
                }
                result += "</table>";

        ss.toast(customColorsArrays+" & "+skipFirstColors+" & "+randomSecondColor, "Output Test", 50);
        ss.show(Html.setTitle("Show the Table at PopUp"));}
}

Я хочу, чтобы при перезагрузке таблицы всегда отображались разные цвета строк каждый раз, когда открывалась страница, и она должна быть установлена ​​с помощью моей персонализации, которую я установил. Пожалуйста, обратите внимание на функцию personalRandomColor () . В этом случае мне бы хотелось, например, Orange только для nth-child (нечетный) и White для nth-child (четный)) при Первое случайное открытие и Красный для n-го ребенка (нечетный) и Синий для n-го ребенка (четный) в Второе случайное открытие и так далее ... и дальше ... и снова, и снова, и всегда снова, но с условием пропуска первых цветов !!!

...