以下のコードで、「 // contact - changeHTML」というコメントアウト以降の処理が反映されなくなってしまいました。
このコメントアウト以前の処理は正常に動いております。
不思議なことにconsoleのエラーは発生しておりません。
原因の予想としては
if (!〇〇){ return false;}が原因なのではないかと思っております。
この記述を逐一、変数後に入れた理由として、例えば特定のWebページのみに存在するアコーディオンメニューの処理を書いた記述が、
他のページだとコンソールエラーを起こしてしまうためです。
※「Uncaught TypeError: Cannot read property 'addEventListener' of null」というエラーが発生します。
対処として以下の記事を参考にして記述するとコンソールエラーは消えました。
https://qiita.com/makky/items/f546df8533c3c3ce9b2f
また、「id名」のミスなどはありませんでした。以前は正常に動いておりました。
ただ、これを消しても結局処理が発生していないのでケアレスミスの可能性もありますが、
どうにも見つけることができないのでお力添えをいただきたいです。
よろしくお願い申し上げます。
コードは以下になります。
window.addEventListener("load",function(){ // swiper const caseSlide = new Swiper('.swiperCase', { loop: true, spaceBetween: 20, slidesPerView: 3, centeredSlides: true, autoplay: { delay: 3000, disableOnInteraction: false, }, breakpoints: { 641: { slidesPerView: 3, spaceBetween: 10, }, 300: { slidesPerView: 1.5, spaceBetween: 10, }, }, }); // swiper const strengthSlide = new Swiper('.swiperStrength', { loop: true, slidesPerView: 1, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); // modal - report const reportPhoto1 = document.getElementById('reportPhoto1'); const reportPhoto2 = document.getElementById('reportPhoto2'); const reportPhoto3 = document.getElementById('reportPhoto3'); const reportPhoto4 = document.getElementById('reportPhoto4'); const reportPhoto5 = document.getElementById('reportPhoto5'); const reportPhoto6 = document.getElementById('reportPhoto6'); if (!reportPhoto1){ return false;} if (!reportPhoto2){ return false;} if (!reportPhoto3){ return false;} if (!reportPhoto4){ return false;} if (!reportPhoto5){ return false;} if (!reportPhoto6){ return false;} reportPhoto1.addEventListener("click",function(){ strengthSlide.slideTo(1); }); reportPhoto2.addEventListener("click",function(){ strengthSlide.slideTo(2); }); reportPhoto3.addEventListener("click",function(){ strengthSlide.slideTo(3); }); reportPhoto4.addEventListener("click",function(){ strengthSlide.slideTo(4); }); reportPhoto5.addEventListener("click",function(){ strengthSlide.slideTo(5); }); reportPhoto6.addEventListener("click",function(){ strengthSlide.slideTo(6); }); // modal const modal = document.getElementById("modal"); if (!modal){ return false;} const modalOpen = document.getElementById("modalOpen"); if (!modalOpen){ return false;} const modalClose = document.getElementById("modalClose"); if (!modalClose){ return false;} modalOpen.addEventListener("click",function(){ modal.classList.add("modalTrigger"); }); modalClose.addEventListener("click",function(){ modal.classList.remove("modalTrigger"); }); // contact - changeHTML const str = document.getElementById('target-1'); if( str ) { const targetStr = str.nextElementSibling; targetStr.innerHTML = '<p class="privacyMessage"><a href="http://timeinterior.local/privacy/" target="_blank" rel="noopener noreferrer">個人情報の取扱について</a>同意します。</p>'; } // drawer const Hamburger = document.getElementById("Hamburger"); if (!Hamburger){ return false;} const drawerMenu = document.getElementById("drawerMenu"); if (!drawerMenu){ return false;} const closeIcon = document.getElementById("closeIcon"); if (!closeIcon){ return false;} const body = document.getElementById("bodyFixed"); if (!body){ return false;} Hamburger.addEventListener("click",function(){ drawerMenu.classList.add("drawerActive"); body.classList.add("bodyFixed"); }); closeIcon.addEventListener("click",function(){ drawerMenu.classList.remove("drawerActive"); body.classList.remove("bodyFixed"); }); // footer - pageTop const pageTop = document.getElementById('pageTop'); if (!pageTop){ return false;} const pageTopArrow = document.getElementById('pageTopArrow'); if (!pageTopArrow){ return false;} const pageTopSub = document.getElementById('pageTopSub'); if (!pageTopSub){ return false;} pageTop.addEventListener("mouseover",function(){ pageTopArrow.classList.add("pageTopActive"); }); pageTop.addEventListener("mouseleave",function(){ pageTopArrow.classList.remove("pageTopActive"); }); pageTop.addEventListener("click",function(){ window.scroll({ top: 0, behavior: 'smooth' }); }); pageTopSub.addEventListener("click",function(){ window.scroll({ top: 0, behavior: 'smooth' }); }); // accordion $(".accordionMenu dt").on("click", function() { $(this).toggleClass("actionDeg") .next().slideToggle(); $(this).toggleClass("shadowNone") }); const target = document.getElementById("columnMore"); if (!target){ return false;} target.addEventListener("mouseover", function (){ document.getElementById("readmoreText").classList.add("active"); document.getElementById("columnMoreIcon > span").classList.add("active"); }); target.addEventListener("mouseleave", function (){ document.getElementById("readmoreText").classList.remove("active"); document.getElementById("columnMoreIcon").classList.remove("active"); document.querySelector("#columnMoreIcon > span").classList.remove("active"); }); // top - changeText document.getElementById("diagramWrapper").addEventListener("mouseover",function(){ if (!diagramWrapper){ return false;} document.getElementById("compareIcon").classList.add("compareActive"); if (!compareIcon){ return false;} document.getElementById("changeText").textContent = "テキストテキスト"; if (!changeText){ return false;} }); document.getElementById("diagramWrapper").addEventListener("mouseleave",function(){ document.getElementById("compareIcon").classList.remove("compareActive"); document.getElementById("changeText").textContent = "テキストテキスト"; }); }); コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/01/25 09:12