微件:FixTableHeader:修订间差异
来自舰R百科
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第2行: | 第2行: | ||
window.onscroll = function() { | window.onscroll = function() { | ||
var tables = document.getElementsByClassName("fix-table-header"); | var tables = document.getElementsByClassName("fix-table-header"); | ||
var | var clone = document.getElementById('fixed-table-header'); | ||
for (var i = 0; i < tables.length; ++i) { | for (var i = 0; i < tables.length; ++i) { | ||
var table = tables[i]; | var table = tables[i]; | ||
var rect = table.getBoundingClientRect(); | var rect = table.getBoundingClientRect(); | ||
if (rect.top < 0 && rect.bottom > 0) { | if (rect.top < 0 && rect.bottom > 0) { | ||
if ( | if (clone == null) { | ||
clone = table.cloneNode(true); | |||
clone.id = 'fixed-table-header'; | |||
clone.style.position = 'fixed'; | |||
clone.style.pointerEvents = 'none'; | |||
clone.style.top = 0; | |||
clone.style.width = table.style.width; | |||
table.parentNode.appendChild( | table.parentNode.appendChild(clone); | ||
clone.style.visibility = 'hidden'; | |||
for (var i = 0; i < | for (var i = 0; i < clone.childNodes.length; i++) { | ||
var hdr = clone.childNodes[i]; | |||
hdr | if (hdr.tagName == 'THEAD') { | ||
hdr.childNodes[i].style. | hdr.style.visibility = 'visible'; | ||
hdr.style.pointerEvents = 'auto'; | |||
hdr.style.backgroundColor = table.childNodes[i].style.backgroundColor; | |||
console.log(hdr.style.backgroundColor); | |||
} | } | ||
} | |||
} | } | ||
return; | return; | ||
} | } | ||
} | } | ||
if ( | if (clone != null) clone.remove(); | ||
} | } | ||
</script><style> #fixed-table-header { background-color: white; } </style></includeonly> | </script><style> #fixed-table-header { background-color: white; } </style></includeonly> | ||