Skip to content

Instantly share code, notes, and snippets.

@manabuyasuda
Last active September 30, 2021 09:26
Show Gist options
  • Select an option

  • Save manabuyasuda/2390f58d9fa51974c5dae94e4ddca5f6 to your computer and use it in GitHub Desktop.

Select an option

Save manabuyasuda/2390f58d9fa51974c5dae94e4ddca5f6 to your computer and use it in GitHub Desktop.
要素が横スクロール可能な状態かを返します。
/**
* 要素が横スクロール可能な状態かを返します。
* @param {HTMLElement} element テーブルをスクロールしている親要素
* @return Boolean
* @example
* const tables = document.querySelectorAll('.table-wrap')
* Array.from(tables).forEach((table) => {
* canScrolled(table) ? canFunc() : notFunc()
* })
*/
const canScrolled = (element) => {
const scrollWidth = element.scrollWidth
const clientWidth = element.clientWidth
const isScrolled = scrollWidth > clientWidth
return isScrolled
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment