我最近尝试在我的网站上设置“ idangero.us刷卡器”功能。不幸的是,它似乎没有用。我在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>
对脚本文件的引用不应位于script元素本身内部。相反,它应该在脚本标签的
src
属性中。像这样:
<script src="//cdn.shopify.com/s/files/1/0659/4529/t/75/assets/swiper.min.js?10728068994914913511">
</script>
tl; dr
掠夺者依赖性消失了。您需要适当地包括它们。