diff --git a/src/App.css b/src/App.css new file mode 100644 index 0000000..5e617bc --- /dev/null +++ b/src/App.css @@ -0,0 +1,15 @@ +.container { +/* display: flex; + flex-direction: column; + flex-wrap: nowrap;*/ + height: 500px; + overflow: auto; + border: 1px solid black; +} +.item { + font-size: 16pt; + border: 1px dotted gray; + /*margin: 5px 10px; + padding: 10px;*/ + border-radius: 5px; +} \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index 531f9c5..8fb1e68 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,45 +1,33 @@ -import { useState, useRef } from 'react' -import './App.scss' +import { useEffect, useRef, useState } from 'react'; +import styles from './App.css'; -function VirtualList({ items, itemHeight=50, containerHeight=400 }) { - const containerRef = useRef(null) - //Положение большого нивидимого контейнера - const [scrollTop,setScrollTop] = useState(0); - //Количество отображаемых элементов - const visibleCount = Math.ceil(containerHeight / itemHeight); - //Общая высота нивидимого контейнера - const totalHeight = items.length * itemHeight; - //Начало и конец подгружаемых(отображаемых) элементов - const startIndex = Math.floor(scrollTop / itemHeight); - const endIndex = Math.min(startIndex + visibleCount + 1, items.length); - //Срез видимых элементов из общего списка - const visibleItems = items.slice(startIndex,endIndex); - - const handleScroll = e => { - setScrollTop(e.target.scrollTop); - console.log(e.target.scrollTop) - } - - return ( -