Blame view

components/thorui/tui-virtual-table/index.js 811 Bytes
46b6767c   刘淇   init 提交到库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  export const mapVirtualToProps = ({
  	items,
  	itemHeight
  }, {
  	startIndex,
  	endIndex
  }) => {
  	const visibleItems = endIndex > -1 ? items.slice(startIndex, endIndex + 1) : []
  
  	// style
  	const height = items.length * itemHeight
  	const paddingTop = startIndex * itemHeight
  
  	return {
  		items: visibleItems,
  		style: `height: ${height}px; padding-top: ${paddingTop}px; box-sizing: border-box;`
  	}
  }
  
  export const getVisibleItemBounds = (viewTop, viewHeight, itemCount, itemHeight, itemBuffer) => {
  	// visible list inside view
  	const listViewTop = Math.max(0, viewTop)
  
  	// visible item indexes
  	const startIndex = Math.max(0, Math.floor(listViewTop / itemHeight) - 12)
  	const endIndex = Math.min(startIndex + Math.ceil(viewHeight / itemHeight) + itemBuffer - 1, itemCount)
  
  	return {
  		startIndex,
  		endIndex,
  	}
  }