我正在使用cycle2,并以编程方式将其设置在单独的scripts.js 文件中。在添加渐进式加载之前,滑块都运行良好。我在页面上有多个滑块,所以设置如下:
$('.slider').each(function () {
var $this = $(this);
$this.cycle({
fx: 'scrollHorz',
slides: '> a',
sync: true,
progressive: slides,
speed: 'fast',
timeout: 0,
autoHeight: 'container',
next: $this.next('.slider-navigation').find('.next'),
prev: $this.next('.slider-navigation').find('.prev'),
loader: true
});
});
我的 HTML 标记是,对于每个滑块,例如:
<div class="slider">
<a href="/">
<img src="example.jpg">
</a>
<script class="other-slides" type="text/cycle">
var slides = [
"<a href=" / "><img src="
another - example.jpg " /></a>",
"<a href=" / "><img src="
another - example.jpg " /></a>",
"<a href=" / "><img src="
another - example.jpg " /></a>"
];
</script>
</div>
但是,现在当我加载页面时,我的控制台状态:ReferenceError: slides is not defined
这是有道理的,因为cycle
init 在 script.js 中并且这个标记在另一个页面上,但是我怎样才能使它工作,或者有更好的方法吗?请记住,页面上有多个滑块。
谢谢,R