ホームページ(1画面のLP)のwordpress化でjavascript(jquery含め)が読み込みがうまくいきません。
functions.php内のfunction twpp_enqueue_scripts以下の記述でmain.jsが呼び出される認識だったのですが、その他にも必要な記述はありますでしょうか。
どなたかご教授いただければと思います。
ローカル環境(MAMP)で動かしています。
javascript
1'use strict'; 2{ 3 //query,ID,class取得 4 const body = document.querySelector("body"); 5 const head = document.getElementById('head') 6 const headLogo = document.getElementById('headLogo'); 7 const menuWrapper = document.getElementById('menuWrapper'); 8 const menuButton = document.getElementById('menuButton'); 9 const nav = document.getElementById('nav'); 10 const moveTop = document.getElementById('moveTop'); 11 const moveAbout = document.getElementById('moveAbout'); 12 const moveProduct = document.getElementById('moveProduct'); 13 const moveContact = document.getElementById('moveContact'); 14 15 //ページ読み込み時処理 16 window.onload = function(){ 17 head.classList.remove('before'); 18 head.classList.add('after'); 19 headLogo.classList.remove('logoHide'); 20 headLogo.classList.add('after'); 21 } 22 23 //読み込み時とリサイズ時、高さを画面いっぱいにする 24 jQuery(function () { 25 jQuery("#head").css("height",jQuery(window).outerHeight()); 26 jQuery(window).resize(function(){ 27 jQuery("#head").css("height",jQuery(window).outerHeight()); 28 }); 29 }); 30 31 //ハンバーガーボタンのアニメーション処理 32 document.addEventListener('DOMContentLoaded', function () { 33 menuButton.addEventListener('click', function (ev) { 34 ev.preventDefault(); 35 this.classList.toggle('active'); 36 }); 37 }); 38 39 //メニューボタン押下時処理 40 menuWrapper.addEventListener('click', function (event) { 41 //メニューが隠れている場合 42 if (nav.classList.contains('close')){ 43 //メニューを開く 44 nav.classList.remove('close'); 45 nav.classList.add('open'); 46 //背景を固定する 47 body.classList.add('fixed'); 48 //メニュー表示中の場合 49 } else { 50 //メニューを閉じる 51 nav.classList.add('close'); 52 nav.classList.remove('open'); 53 //背景固定を解除 54 body.classList.remove('fixed'); 55 } 56 }); 57 58 //スクロール処理 59 jQuery(function(){ 60 // #で始まるリンクをクリックしたら実行されます 61 jQuery('a[href^="#"]').click(function() { 62 // スクロールの速度 63 var speed = 300; // ミリ秒で記述 64 var href= jQuery(this).attr("href"); 65 var target = jQuery(href == "#" || href == "" ? 'html' : href); 66 var position = target.offset().top; 67 jQuery('body,html').animate({scrollTop:position}, speed, 'swing'); 68 return false; 69 }); 70 }); 71 72 /********** サブメニュー処理ここから **********/ 73 //Top押下時処理 74 moveTop.addEventListener('click', () => { 75 nav.classList.add('close');//メニューを閉じる 76 body.classList.remove('fixed');//背景固定を解除 77 menuButton.classList.remove('active');//メニューボタンを戻す 78 }); 79 80 //about押下時処理 81 moveAbout.addEventListener('click', () => { 82 nav.classList.add('close');//メニューを閉じる 83 body.classList.remove('fixed');//背景固定を解除 84 menuButton.classList.remove('active');//メニューボタンを戻す 85 }); 86 87 //Servive押下時処理 88 moveProduct.addEventListener('click', () => { 89 nav.classList.add('close');//メニューを閉じる 90 body.classList.remove('fixed');//背景固定を解除 91 menuButton.classList.remove('active');//メニューボタンを戻す 92 }); 93 94 //Contact押下時処理 95 moveContact.addEventListener('click', () => { 96 nav.classList.add('close');//メニューを閉じる 97 body.classList.remove('fixed');//背景固定を解除 98 menuButton.classList.remove('active');//メニューボタンを戻す 99 }); 100 /********** サブメニュー処理ここまで **********/ 101 102} 103
PHP
1//functions.php 2<?php 3 4add_theme_support('menus'); 5 6function twpp_enqueue_scripts() { 7 wp_enqueue_script( 8 'main-script', 9 get_template_directory_uri() . '/js/main.js' 10 ); 11} 12add_action( 'wp_enqueue_scripts', 'twpp_enqueue_scripts' ); 13
PHP
1//index.php 2<!DOCTYPE html> 3<html> 4<head> 5 省略 6 <?php wp_head(); ?> 7</head> 8<header> 9省略 10</header> 11<main> 12省略 13</main> 14<footer> 15省略 16</footer> 17<?php wp_footer(); ?> 18<script src="js/jquery-3.4.1.min.js"></script> 19<script src="js/main.js"></script> 20
回答1件
あなたの回答
tips
プレビュー