LoginSignup
0
0

More than 3 years have passed since last update.

Observerを使ってDOMを監視するサンプル めも

Posted at
Observerをつかて、要素を監視して
gdpがshowになったら何かするサンプルっぽい
<script>

//  observeForTargetElement = document.getElementById("div-gpt-ad-1733-0");
//  // intersection
//  let intersection = new IntersectionObserver(function(entry) {
//    console.log(entry[0].intersectionRatio)
//
//    //googletag.cmd.push(function() {
//    //  googletag.display('div-gpt-ad-1733-0');
//    //})
//
//    //監視の停止(実際には特定条件下で実行)
//    let shouldStopObserving = false;
//    if (shouldStopObserving) {
//      intersection.disconnect();
//    }
//
//  }, {root: null, rootMargin: "0px", threshold: buildThresholdList()});
//  intersection.observe(observeForTargetElement);
//
//
//  function buildThresholdList() {
//    let thresholds = [];
//    for (let i = 1.0; i <= 10; i++) {
//      thresholds.push(i / 10);
//    }
//    thresholds.push(0);
//    return thresholds;
//  }


</script>
0
0
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
0