0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

domをいじってclassを付加(モーダルの出現中にページスクロールをさせない、一定の高さスクロールしたらtableのheaderを固定する等)

Posted at

document.getElementById('hogeID').classList.add('fix')

document.getElementById('hogeID').classList.remove('fix')

document.body.classList.remove('no-scroll')

document.getElementsByClassName('test')[0]

例:一定の高さスクロールしたらtableのheaderを固定する

/**
 * tableのheaderを固定処理
 */
onScroll(e) {
  const fixTableTop = document.getElementById('fugaID').getBoundingClientRect().top

  if (fixTableTop < 140) {
    document.getElementById('tableHeader').classList.add('fix')
  } else {
    document.getElementById('tableHeader').classList.remove('fix')
  }
},

##参考

####Document.getElementsByClassName()
https://developer.mozilla.org/ja/docs/Web/API/Document/getElementsByClassName

####Element.getBoundingClientRect()
https://developer.mozilla.org/ja/docs/Web/API/Element/getBoundingClientRect

####モーダルを開いている時にページがスクロールしてしまうのを防ぐCSSとJavaScriptのテクニック
https://coliss.com/articles/build-websites/operation/javascript/prevent-page-scrolling-when-a-modal-is-open.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?