【发布时间】:2014-10-21 19:26:53
【问题描述】:
我正在使用Slick carousel jQuery 插件。在docs 中有一个选项appendArrows。据我了解,它可用于使箭头粘在不同的元素上。我使用一个嵌套的轮播,这样每张幻灯片都有一个标题、链接、描述,而不是几个图片子幻灯片。使用默认设置,导航箭头位于整个幻灯片的中心。我希望它们只附加到图片中,但我不知道该怎么做。 appendArrows: $('img’) 不起作用。
这是标记:
<div class="slider-for">
<div class="single-item">
<h4>Title</h4>
<a href=“#” target="_blank">example.com</a>
<p>Description.</p>
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
</div>
<div class="single-item">
<h4>Title</h4>
<a href=“#” target="_blank">example.com</a>
<p>Description.</p>
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
</div>
<div class="single-item">
<h4>Title</h4>
<a href=“#” target="_blank">example.com</a>
<p>Description.</p>
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
<img class="img-responsive" src="http://placehold.it/960x540">
</div>
</div>
还有 JS:
$('.slider-for').slick({
slidesToShow: 1,
slidesToScroll: 1,
fade: true,
swipe: false,
accessibility: false,
arrows: false,
});
$('.single-item').slick({
slide: 'img',
dots: true,
speed: 500,
arrows: true,
appendArrows: $('img'),
});`
编辑:我认为这个问题不清楚,我的错。 .slider-for 由我在示例中省略的.slider-nav 切换。一切正常,我的问题更多是美学问题。当箭头附加到整个 .single-item 时,它们垂直居中于整个 <div class="single-item"> 的高度,这看起来很奇怪,因为它里面只有 <img>s 实际上在滑动。我想将箭头附加到<img>'s,以便它们垂直居中于图像的高度。我希望这更有意义。
我想我真正要问的是:如何使用appendArrows() 定位<div class="single-item"> 内部的<img>?文档状态:
选项:appendArrows;类型:字符串;默认值:$(元素);描述:改变 附加导航箭头的位置(选择器、htmlString、数组、 元素,jQuery 对象)
我该如何使用它?请记住,我是一个初学者,我不太了解 JS,所以我可能遗漏了一些明显的东西。
【问题讨论】:
-
appendArrows 可能只接受唯一的容器元素,即元素 ID。你能发布一个jsfiddle吗?
-
所以我应该添加例如
#slide到<img>,然后是appendArrows: $('#slide')?由于我现在不在家,所以我无法制作 jsfiddle。 -
没有。 ID 在页面上必须是唯一的。此外,您不应该尝试将箭头附加到每个图像元素。 appendArrows 函数仅用于将左/右箭头附加到单个 DOM 元素。您应该将它们附加到 .slider-for 元素。
-
当然你对 ID 的看法是正确的。菜鸟错误。 ;) 正如我在 Gregory 的回答下的其中一个 cmets 中所说,我希望箭头在
.single-item内切换<img>,.slider-for由我在示例代码中省略的.slider-nav处理.我怀疑我的问题不清楚,应该提供整个代码。对此感到抱歉。
标签: javascript jquery jquery-plugins carousel slick.js