idangero.us swiper - “Swiper未定义”错误

时间:2016-06-22 14:41:11

标签: javascript swiper

我最近尝试在我的网站上设置“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>

2 个答案:

答案 0 :(得分:0)

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

<!-- 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;博士

缺少swiper依赖项。你需要正确地包括它们。

答案 1 :(得分:0)

即使您没有将链接swiper.js文件的脚本标签放在顶部的顶部,也会出现此错误。