-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.stickytable.min.js
1 lines (1 loc) · 4.17 KB
/
jquery.stickytable.min.js
1
jQuery(document).on("stickyTable",function(){var t,s=((t=document.createElement("a").style).cssText="position:sticky;position:-webkit-sticky;position:-ms-sticky;",-1!==t.position.indexOf("sticky")),i=function(){var t=$('<div dir="rtl" style="font-size: 14px; width: 4px; height: 1px; position: absolute; top: -1000px; overflow: scroll">ABCD</div>').appendTo("body")[0],s="reverse";return t.scrollLeft>0?s="default":(t.scrollLeft=1,0===t.scrollLeft&&(s="negative")),$(t).remove(),s}();if(s){var e=0;$(".sticky-table").each(function(){e=0,$(this).find("table tr.sticky-header").each(function(){$(this).find("th").css("top",e),$(this).find("td").css("top",e),e+=$(this).outerHeight()}),e=0,$($(this).find("table tr.sticky-footer").get().reverse()).each(function(){$(this).find("th").css("bottom",e),$(this).find("td").css("bottom",e),e+=$(this).outerHeight()})}),$(".sticky-ltr-cells table tr").each(function(){e=0,$(this).find(".sticky-cell").each(function(){$(this).css("left",e),e+=$(this).outerWidth()}),e=0,$($(this).find(".sticky-cell-opposite").get().reverse()).each(function(){$(this).css("right",e),e+=$(this).outerWidth()})})}else navigator.userAgent.match(/Trident\/7\./)&&$(".sticky-table").on("mousewheel",function(t){t.preventDefault();var s=t.originalEvent.wheelDelta,i=$(this).scrollTop();$(this).scrollTop(i-s)}),$(".sticky-table").scroll(function(){$(this).find("table tr.sticky-header th").css("top",$(this).scrollTop()),$(this).find("table tr.sticky-header td").css("top",$(this).scrollTop());var t=$(this).find("table").prop("clientHeight")-$(this).prop("clientHeight");$(this).find("table tr.sticky-footer th").css("bottom",t-$(this).scrollTop()),$(this).find("table tr.sticky-footer td").css("bottom",t-$(this).scrollTop())}).scroll(),$(".sticky-ltr-cells").scroll(function(){$(this).find("table th.sticky-cell").css("left",$(this).scrollLeft()),$(this).find("table td.sticky-cell").css("left",$(this).scrollLeft());var t=$(this).find("table").prop("clientWidth")-$(this).prop("clientWidth");$(this).find("table th.sticky-cell-opposite").css("right",t-$(this).scrollLeft()),$(this).find("table td.sticky-cell-opposite").css("right",t-$(this).scrollLeft())}).scroll();!$(".sticky-rtl-cells").length||s&&"negative"==i||(s&&($(".sticky-rtl-cells table th.sticky-cell").css("position","relative"),$(".sticky-rtl-cells table td.sticky-cell").css("position","relative"),$(".sticky-rtl-cells table th.sticky-cell-opposite").css("position","relative"),$(".sticky-rtl-cells table td.sticky-cell-opposite").css("position","relative"),$(".sticky-table").scroll(function(){$(this).find("table tr.sticky-header .sticky-cell").css("top",$(this).scrollTop()),$(this).find("table tr.sticky-header .sticky-cell-opposite").css("top",$(this).scrollTop());var t=$(this).find("table").prop("clientHeight")-$(this).prop("clientHeight");$(this).find("table tr.sticky-footer .sticky-cell").css("bottom",t-$(this).scrollTop()),$(this).find("table tr.sticky-footer .sticky-cell-opposite").css("bottom",t-$(this).scrollTop())}).scroll()),$(".sticky-rtl-cells").scroll(function(){var t=$(this).find("table").prop("clientWidth")-$(this).prop("clientWidth");switch(i){case"default":$(this).find("table th.sticky-cell").css("right",t-$(this).scrollLeft()),$(this).find("table td.sticky-cell").css("right",t-$(this).scrollLeft()),$(this).find("table th.sticky-cell-opposite").css("left",$(this).scrollLeft()),$(this).find("table td.sticky-cell-opposite").css("left",$(this).scrollLeft());break;case"negative":$(this).find("table th.sticky-cell").css("right",-1*$(this).scrollLeft()),$(this).find("table td.sticky-cell").css("right",-1*$(this).scrollLeft()),$(this).find("table th.sticky-cell-opposite").css("left",t+$(this).scrollLeft()),$(this).find("table td.sticky-cell-opposite").css("left",t+$(this).scrollLeft());break;case"reverse":$(this).find("table th.sticky-cell").css("right",$(this).scrollLeft()),$(this).find("table td.sticky-cell").css("right",$(this).scrollLeft()),$(this).find("table th.sticky-cell-opposite").css("left",t-$(this).scrollLeft()),$(this).find("table td.sticky-cell-opposite").css("left",t-$(this).scrollLeft())}}).scroll()),$(window).resize(function(){$(".sticky-table").scroll()})}),$(document).ready(function(){$(document).trigger("stickyTable")});