From 7cabecae9da4453cef89d236c4cc873889bf8ff3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 20 Oct 2017 20:12:30 +0200 Subject: [PATCH] Factor out fading. --- carousel.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/carousel.js b/carousel.js index a362891..4263995 100644 --- a/carousel.js +++ b/carousel.js @@ -319,14 +319,12 @@ var display_group = function(response, group_name) { addtd(tr, "gd", teams[i].gd.toString().replace(/-/, '−')); addtd(tr, "pts", teams[i].pts); - tr.style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + 0.25 * (row_num++) + "s; -webkit-animation-fill-mode: both;"; carousel.appendChild(tr); } if (tiebreakers.length > 0) { var tie_tr = document.createElement("tr"); tie_tr.className = "footer"; - tie_tr.style = "-webkit-animation: fade-in 2.0s ease; -webkit-animation-delay: " + 0.25 * (row_num++) + "s; -webkit-animation-fill-mode: both;"; var td = document.createElement("td"); td.appendChild(document.createTextNode("Tiebreaks applied: " + tiebreakers.join(', '))); td.setAttribute("colspan", "5"); @@ -336,16 +334,29 @@ var display_group = function(response, group_name) { var footer_tr = document.createElement("tr"); footer_tr.className = "footer"; - footer_tr.style = "-webkit-animation: fade-in 2.0s ease; -webkit-animation-delay: " + 0.25 * (row_num++) + "s; -webkit-animation-fill-mode: both;"; var td = document.createElement("td"); td.appendChild(document.createTextNode("www.trondheimfrisbeeklubb.no | #trøndisk")); td.setAttribute("colspan", "5"); footer_tr.appendChild(td); carousel.appendChild(footer_tr); + fade_in_rows(carousel); + carousel.style.display = 'table'; }; +var fade_in_rows = function(table) +{ + var trs = table.getElementsByTagName("tr"); + for (var i = 1; i < trs.length; ++i) { // The header already has its own fade-in. + if (trs[i].className === "footer") { + trs[i].style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;"; + } else { + trs[i].style = "-webkit-animation: fade-in 2.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;"; + } + } +}; + // Stream schedule var display_stream_schedule = function(response, group_name) { var teams = parse_teams_from_spreadsheet(response); @@ -398,10 +409,12 @@ var display_stream_schedule_parsed = function(teams, games) { addth(tr, "streamtime", games[i].streamtime); } - tr.style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + 0.25 * (row_num++) + "s; -webkit-animation-fill-mode: both;"; + row_num++; carousel.appendChild(tr); } + fade_in_rows(carousel); + carousel.style.display = 'table'; }; -- 2.39.2