Właściwości overflow:auto jest ustawiony w div'ie i następuje jego przepełnienie, jak w takim przypadku sprawdzić, czy pojawił się pasek przewijania, za pomocą CSS.
0
2
Można to sprawdzić porównując właściwości scrollWidth
i clientWidth
, oraz analogicznie scrollHeight
, oraz clientHeight
.
const element = document.querySelector('#element');
const hasHorizontalScrollbar = element.scrollWidth > element.clientWidth; // true lub false
const hasVerticalScrollbar = element.scrollHeight > element.clientHeight; // true lub false
clientWidth / clientHeight -> wysokość / szerokość elementu bez marginesów i scrollbara.
scrollWidth / scrollHeight -> wysokość / szerokość elementu bez marginesów, ale wliczając scrollbar.