-1

I would like to add a background color to a list to make scrolling look better but I only want to it if the list is scrollable. How might I configure this?

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

1 Answers1

1

You can use this simple check and modify to meet your needs:

const dimensions = document.querySelector('selector').getBoundingClientRect();
if(dimensions.height > window.innerHeight) {
    // Element's height is bigger than window height, so it should be scrollable
    document.querySelector('selector').style('background', '#222');
}

You can test whether the height of the element is greater than the height of it's container.

Chase DeAnda
  • 15,963
  • 3
  • 30
  • 41
  • Idk, you didn't post any code or context so I have no idea what your use case is and what your app setup is. This is as far as I can help with the info you provided in your question. – Chase DeAnda Mar 28 '18 at 14:26
  • Thanks for your answer. The context is in the tag. :) – Ian Warburton Mar 29 '18 at 13:28