(target: JQuery, container: JQuery, position = 'top', complete?: (this: HTMLElement) => void, offset = 0)
| 102 | |
| 103 | // container 为带有滚动条的元素 |
| 104 | export function box_scroll_to(target: JQuery, container: JQuery, position = 'top', complete?: (this: HTMLElement) => void, offset = 0) { |
| 105 | let scrollTopOffset = null; |
| 106 | if (position === 'top') |
| 107 | scrollTopOffset = target[0].getBoundingClientRect().top - container[0].getBoundingClientRect().top; |
| 108 | else if (position === 'middle') |
| 109 | scrollTopOffset = target[0].getBoundingClientRect().top - container[0].getBoundingClientRect().top - container.height() * 0.5 + target.height() * 0.5; |
| 110 | else if (position === 'bottom') |
| 111 | scrollTopOffset = target[0].getBoundingClientRect().bottom - container[0].getBoundingClientRect().bottom; |
| 112 | |
| 113 | let speed = Math.min(Math.abs(scrollTopOffset + offset), 500) + 100; |
| 114 | if (scrollTopOffset !== null) |
| 115 | container.stop().animate({scrollTop: container.scrollTop() + scrollTopOffset + offset}, speed, complete); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | export function randomid(length: number) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…