前提・実現したいこと
背景が全面画像のシングルページレイアウトのホームページを作っているのですが、Swiperでスライドショーを実装中に以下のような問題が発生しました。
情報量が多くて大変かもしれませんが、よろしくおねがいいたします。
発生している問題・エラーメッセージ
スライドショーが正しく動かない。具体的には以下の通り。
・次のスライドが表示されない。
・スライドショーに設定した残りの画像が下の方に続けて表示される。
・ページ番号が正しく表示されない。
エラーメッセージ
使用しているBracketsでは「29個のJSLintの問題」の下に
・'JQuery' was used before it was defined.
と表示される。
他にもGoogleChromeのデベロッパーツールで
・Uncaught ReferenceError: $fixedMenu is not defined
と表示される。
該当のソースコード
●●●HTML●●●
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>base</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="This is a sample of fixed-navigation."> <meta name="keywords" content="navigation, fixed, css"> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/swiper.css"> <link rel="stylesheet" href="css/style.css"> </head> <body> <header> <h1>花火大会</h1> </header></body> </html><div id="nav-container"> <nav id="fixed-nav"> <ul> <li><a href="#">Top</a></li> <li><a href="#">About</a></li> <li><a href="#">Guide</a></li> <li><a href="#">Gallery</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </div> <div class="swiper-container"> <div id="swiper-wrapper"> <div class="swiper-slide"><img src="images/slide1.jpg" alt=""></div> <div class="swiper-slide"><img src="images/slide1.jpg" alt=""></div> <div class="swiper-slide"><img src="images/slide1.jpg" alt=""></div> <div class="swiper-slide"><img src="images/slide1.jpg" alt=""></div> </div> <div class="swiper-pagination"></div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> <section id="main"> <h1>ここに本文が入ります。</h1> </section> <script src="js/jquery-3.4.1.min.js"></script> <script src="js/swiper.js"></script> <script src="js/script.js"></script>
●●●CSS●●●
@charset "utf-8";
/* 背景に画像を配置 */
html {
min-height: 100%;
}
/* ナビゲーションエリアの高さ分の補正 /
#nav-container {
margin-top: -90px;
padding-top: 90px;
}
body {
background-image: url(../images/fireworks3.jpg);
background-position: center center;
background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
margin: 0;
padding: 0;
}
/ ヘッダーの設定 /
header {
width: 100%;
overflow: hidden;
}
header h1 {
font-style: normal;
color: white;
text-align: center;
font-size: 96px;
margin: 30px 0 20px 0;
padding: 0;
text-shadow: 2px 2px 20px black;
overflow: hidden;
}
/ ナビゲーションエリアの設定 /
nav {
text-align: center;
margin: 0px;
padding: 0;
width: 100%;
}
nav ul {
margin-top: 0px;
padding: 0;
width: 100%;
}
nav ul li {
list-style: none;
display: inline-block;
width:92px;
min-width: 92px;
}
nav ul li a {
display: inline-block;
text-align: center;
text-decoration: none;
color: black;
background-color: white;
font-size: 23px;
font-style: normal;
font-family:fantasy;
width: 80px;
height: 80px;
line-height: 80px;
border: 5px double black;
border-radius: 50%;
vertical-align: middle;
overflow: hidden;
transition: .8s;
}
nav ul li a:hover {
background-color: yellow;
color: black;
}
.fixed {
position: fixed;
top: 0;
width: 100%;
z-index: 999;
}
/ swiperの設定 /
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
position: relative;
}
@media screen and (max-width: 600px) {
.swiper-slide img {
width: 100%;
height: 100%;
}
}
.swiper-pagination-bullet-active {
width: 10px;
height: 10px;
background-color: red;
}
/ メイン領域の設定 */
#main {
background-color: white;
background-position: center center;
width: 80%;
height: 100%;
margin: 80px auto 0 auto;
}
#main h1 {
font-style: normal;
color: white;
text-align: center;
font-size: 40px;
margin-top: 30px;
margin-bottom: 1000px;
padding: 0;
text-shadow: 2px 2px 20px black;
}
●●●Javascript●●●
jQuery(function($) {
var nav = $('#fixed-nav'),
offset = nav.offset();
$(window).scroll(function () {
if($(window).scrollTop() > offset.top) {
nav.addClass('fixed');
} else {
nav.removeClass('fixed');
}
});
$(window).scroll($fixedMenu);
// スマートフォン用に touchmove を使う
$('body').bind('touchmove', $fixedMenu);
// スライドの制御 // var swiper = new Swiper('.swiper-container', { navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, loop: true, pagination: { el: '.swiper-pagination', type: 'bullets', }, autoplay: { delay: 3000, disableOnInteraction: true, }, autoHeight: true, });
});
試したこと
ナビゲーションを切り離すのは試したのですが、同じ事になりました。
練習用に作ったほぼ同じ構文の別のスライドショーは正しく動作しています。
補足情報(FW/ツールのバージョンなど)
背景に全面画像使用
上部固定のナビゲーションエリア実装済(特定のタイミングで固定)
回答1件
あなたの回答
tips
プレビュー