gpt4 book ai didi

javascript - idangero.us swiper - "Swiper not defined"错误

转载 作者:行者123 更新时间:2023-11-28 05:52:36 30 4
gpt4 key购买 nike

我最近尝试在我的网站上设置“idangero.us Swiper”功能。不幸的是,它似乎不起作用。我对 JS 的经验非常有限,所以我完全不知道如何解决这个问题。

我收到的错误是Uncaught ReferenceError: Swiper is not Defined

感谢您提供的任何帮助。 http://www.hollywoodfeed.com/pages/catalog-page-1

我的 HTML 是

<!-- Swiper -->
<style>
.swiper-container{
width:100%;
height:auto;
margin:20px auto;
}
.swiper-slide{
text-align:center;
font-size:18px;
background:#fff;
line-height:300px;
}
</style>

<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>

<div class="swiper-pagination"></div>

<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>

JS

<!-- Swiper Include Files -->
<script> {{ 'swiper.min.js' | asset_url }}</script>

<script>
var swiper;
$(document).ready(function () {
var swiper = new Swiper('.swiper-container', {
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
pagination: '.swiper-pagination',
paginationType: 'fraction'
})
});
</script>

最佳答案

在我看来,无论您使用什么模板系统,都不会将依赖脚本文件放在页面上。

<!-- Swiper Include Files -->
<script> {{ 'swiper.min.js' | asset_url }}</script>

上面的脚本输出以下内容:

<script>     
//cdn.shopify.com/s/files/1/0659/4529/t/75/assets/swiper.min.js?10728068994914913511
</script>

对脚本文件的引用不应位于脚本元素本身内部。相反,它应该位于脚本标签 src 属性中。就像这样:

<script src="//cdn.shopify.com/s/files/1/0659/4529/t/75/assets/swiper.min.js?10728068994914913511">
</script>
<小时/>

tl;博士

缺少滑动器依赖项。您需要正确地包含它们。

关于javascript - idangero.us swiper - "Swiper not defined"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37971335/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com