scroll.sjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function handleScroll(event, ownerComponent) {
  2. var currentScroll = event.detail.scrollTop;
  3. var dataset = event.instance.getDataset();
  4. var elementSize = dataset.elementsize,
  5. monthList = dataset.monthlist;
  6. if (!elementSize) {
  7. return;
  8. }
  9. // 组件如果内嵌在 slot 里, 一定会被渲染出来, 但是此时 cellHight 为 0
  10. if (elementSize.cellHight === 0) {
  11. ownerComponent.callMethod('measurement');
  12. return;
  13. }
  14. var instance = ownerComponent.selectComponent('.ant-calendar-sticky-title');
  15. var sticky = ownerComponent.selectComponent('.ant-calendar-sticky');
  16. if (sticky) {
  17. sticky.setStyle({
  18. display: currentScroll < 0 ? 'none' : 'block'
  19. });
  20. }
  21. var monthHeight = elementSize.monthTitleHeight;
  22. var paddingHeight = elementSize.paddingHeight;
  23. var cellHeight = elementSize.cellHight;
  24. var heightList = monthList.map(function (p) {
  25. return monthHeight + cellHeight * p.cells.length / 7;
  26. });
  27. for (var i = 0; i < heightList.length; i++) {
  28. if (currentScroll < heightList[i]) {
  29. var topHeight = currentScroll - heightList[i] + monthHeight - paddingHeight;
  30. topHeight = Math.max(topHeight, 0);
  31. instance.setStyle({
  32. transform: "translateY(-".concat(topHeight, "px)")
  33. });
  34. ownerComponent.callMethod('setCurrentMonth', {
  35. month: topHeight > monthHeight * 0.8 ? i + 1 : i
  36. });
  37. break;
  38. } else {
  39. currentScroll = currentScroll - heightList[i];
  40. }
  41. }
  42. }
  43. export default {
  44. handleScroll: handleScroll
  45. };