schedule width fix

This commit is contained in:
tmshv committed 2016-02-15 22:23:18 +03:00
1 parent 7bd7ea5ee8
commit a1793f7cbe
1 file changed
+18 -7
+18 -7
View File
@@ -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');
}