当前位置 : 主页 > 网络编程 > JavaScript >

滚动会议室列表到当前时段

来源:互联网 收集:自由互联 发布时间:2021-06-28
meeting-scroll.js javascript: void ((() = { /*自动滚动到当前时段 v1.0.0*/ const getHour = (date) = { let d; if (date) { d = new Date(date); } else { d = new Date(); } return d.getHours(); }; const gen = (api) = { return (doms, fn)
meeting-scroll.js
javascript: void ((() => {
  /*自动滚动到当前时段 v1.0.0*/
  const getHour = (date) => {
    let d;
    if (date) {
      d = new Date(date);
    } else {
      d = new Date();
    }
    return d.getHours();
  };

  const gen = (api) => {
    return (doms, fn) => {
      return Array.prototype[api].call(doms, fn);
    };
  };

  const map = gen('map');
  const filter = gen('filter');

  const condition = (curTime = getHour()) => {
    return (item) => {
      return item.textContent.startsWith(curTime);
    };
  };

  const getDomTime = (roomDetail) => {
    const times = roomDetail.querySelectorAll('.time');
    const o = filter(times, condition());
    if (o.length) {
      return o[0];
    }
    return null;
  };

  const HeaderHeight = document.querySelector('#schedule-content .description').offsetHeight;/*表头遮盖高度*/
  const roomDetail = document.querySelectorAll('.room-detail');

  map(roomDetail, item => {
    let room = getDomTime(item);
    if (room) {
      item.scrollTop = room.offsetTop - HeaderHeight;
    }
  });
})())
网友评论