123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- let floatTitleNum = 0;
- let floatTitleMap = new Map();
- var floatTitle = (function () {
- const setFloatTitle = function () {
- const content = $("#content");
- const contentTop = content.offset().top;
- const contentOuterHeight = content.outerHeight(true); //当前可视的页面高度
- //遍历
- $('#tableContent tr').each(function () {
- const content = $(this).children().eq(0).html();
- if (content !== null && content !== undefined && content.length > 0 && content !== " ") {
- let cardOffsetTop = $(this).offset().top;
- let cardOuterHeight = $(this).outerHeight(true);
- if ((cardOffsetTop + cardOuterHeight - 10 > contentTop) &&
- (cardOffsetTop < contentTop + contentOuterHeight)) {
- const floatTitleDiv = $("#floatTitle");
- const value = $(this).data("value");
- if (value !== undefined && value !== null) {
- floatTitleDiv.removeClass("none");
- floatTitleDiv.html(floatTitleMap.get(value));
- } else {
- $('#floatTitle').addClass("none")
- }
- return false
- }
- }
- });
- }
- const setFloatTitleMap = function () {
- $('#tableContent tr').each(function () {
- const content = $(this).children().eq(0).html();
- if (content !== null && content !== undefined && content.length > 0 && content !== " ") {
- const titleId = $(this).data("title");
- if (titleId !== undefined && titleId !== null) {
- floatTitleMap.set(titleId, content);
- }
- }
- });
- }
- //监听上下滚动
- const callFloatTitleSetTimeout = function (floatTitleNumTemp) {
- if (floatTitleNum === floatTitleNumTemp) {
- setFloatTitle();
- }
- }
- const callFloatTitle = function () {
- if (floatTitleNum > 100000) {
- floatTitleNum = 0;
- } else {
- floatTitleNum++;
- }
- const floatTitleNumTemp = floatTitleNum
- setTimeout(function () {
- callFloatTitleSetTimeout(floatTitleNumTemp)
- }, 50);
- }
- return {callFloatTitle, setFloatTitleMap}
- })();
|