diff --git a/src/client/modules/schedule.js b/src/client/modules/schedule.js index 9aae7a42..c72403c3 100644 --- a/src/client/modules/schedule.js +++ b/src/client/modules/schedule.js @@ -41,7 +41,22 @@ module.exports = angular.module('hudozka.schedule', []) var $tbody = element.find('table tbody'); var $thead = element.find('table thead'); - var $td_list = []; + + let setHeadWidth = () => { + var $td_list = element.find('table tbody tr:first-child td'); + $td_list.each(function (i) { + var w = this.offsetWidth; + $thead.find('th')[i].style.width = `${w}px`; + }); + }; + + let resetHeadWidth = () => { + var $td_list = element.find('table tbody tr:first-child td'); + $td_list.each(function (i) { + var w = this.offsetWidth; + $thead.find('th')[i].style.width = null; + }); + }; var min; var max; @@ -50,17 +65,13 @@ module.exports = angular.module('hudozka.schedule', []) if(!min) min = element.find('table tbody tr:first-child')[0].offsetTop + scrollOffset; if(!max) max = element.find('table tbody tr:last-child')[0].offsetTop + scrollOffset; - if(!$td_list.length) $td_list = element.find('table tbody tr:first-child td'); - $td_list.each(function (i) { - var w = this.offsetWidth; - $thead.find('th')[i].style.width = `${w}px`; - }); - var scroll = $(this).scrollTop(); if (scroll >= min && scroll <= max) { + setHeadWidth(); $thead.addClass('fix animated fadeInDown'); $tbody.addClass('fix'); } else { + resetHeadWidth(); $thead.removeClass('fix animated fadeInDown'); $tbody.removeClass('fix'); }