前提
HPが作りたくて、最近始めた初心者です。
インターセクションオブザーバーを実装したいのですが、
classListの追加?でつまずいています。
add("active")のところで定義がないというエラーになってしまいました。
js
1let ddd = document.querySelector("#d_1"); 2let eee = document.querySelector("#e_1"); 3 4 5//関数 6let imgActive = (entries) => { 7 console.log(entries); 8 entries.forEach(entry => { 9 if(entry.isIntersecting) { 10 entry.terget.classList.add("active"); 11 } 12 }); 13} 14 15let options = { 16 threshold: 0.5 17}; 18 19 20//監視 21let observer = new IntersectionObserver(imgActive,options); 22 23observer.observe(ddd); 24observer.observe(eee);
実現したいこと
オブザーバーが機能するようにしたい。
発生している問題・エラーメッセージ
Uncaught TypeError: Cannot read properties of undefined (reading 'classList')
該当のソースコード
js
1let imgActive = (entries) => { 2 console.log(entries); 3 entries.forEach(entry => { 4 if(entry.isIntersecting) { 5 entry.terget.classList.add("active"); 6 } 7 }); 8}
試したこと
他の方法も試したのですが、この書き方が一番進みました。
少し書き方を変えてもみましたが、変わらずエラーになります…。
補足情報(FW/ツールのバージョンなど)
Visual Studio Codeを使用しています。
まだ不慣れで、説明も分かりにくいかもですが、教えてくれると嬉しいです。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー