0

なぜこれがうまくいかないのですか?私の場合、Amp-script を使用しています。ログは成功していますが、サンプル コードは実際には機能しません。

<amp-script script="btn-obs" layout="responsive" height="300" width="300" >
    <input class="load-more" id="btnloadmore" type="submit" value="TEST BTN" on="tap:formme.submit" tabindex="0" role="button"> 
</amp-script>

<script id="btn-obs" type="text/plain" target="amp-script">
    const loadmore = document.querySelector('#btnloadmore');
    
    loadmore.addEventListener("click", () => {
       console.log("cliked");
    });
    var left;
    var right;
    var bottom;
    var top;
       window.addEventListener("scroll", function(event){
       let target = loadmore;
       target.getBoundingClientRectAsync().then(coords => {
           left = coords.left; 
           top = coords.top;
           bottom = coords.bottom;
           right = coords.right;
          });
          
          
          
        const isInViewport = top >= 0 &&
        left >= 0 &&
        bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        right <= (window.innerWidth || document.documentElement.clientWidth);
        
        
        if(isInViewport == true){
            loadmore.click();
            console.log("yes")
        }
    });
</script>

そして、次のようなエラーが発生しました:

[amp-script] Uncaught TypeError: 未定義のプロパティを読み取ることができません (「クリック」を読み取ります)

4

0 に答える 0