光滑的滑块移动幻灯片上方的幻灯片

时间:2016-08-08 05:46:21

标签: javascript jquery html

目前我正在初始化我的滑块

JS

$('.responsive-slider').slick({
  nextArrow: '<span class="slick-divider right"></span><i class="fa fa-chevron-right"></i>',
  prevArrow: '<span class="slick-divider left"></span><i class="fa fa-chevron-left"></i>',
  dots: true,
  infinite: false,
  speed: 300,
  slidesToShow: 6,
  slidesToScroll: 6,
});

PHP

<div class="responsive-slider feat-slider-container">
  <?php foreach ($products as $i => $product) { $i=$i+1; ?>
  <div class="slide" itemscope itemtype="http://schema.org/Product">
    <div class="overlay__container relative">
      <a href="<?php echo $product['href']; ?>" title="<?php echo $product['name'];?>">
        <img
        src="<?php $product['thumb'] = preg_replace('/(http:\/\/gd\d.alicdn.com)/', 'https://img.alicdn.com', $product['thumb']); echo $product['thumb']; ?>"
        itemprop="image"
        alt="<?php echo $product['name']; ?>"
        title="<?php echo $product['name'];?>"
        class="img-responsive" />
        <span itemprop="name" class="slider--name" title="<?php echo $product['name'];?>"><?php echo $product['pname']; ?></span>
      </a>
    </div>
    <div class="slide__caption">
      <div class="price">
        <span><?php echo $product['price']; ?></span>
      </div>
    </div>
  </div>
  <?php } ?>
</div>

HTML

<div class="responsive-slider feat-slider-container slick-initialized slick-slider" role="toolbar"><span class="slick-divider left slick-arrow slick-disabled" aria-disabled="true" style="display: block;"></span><i class="fa fa-chevron-left slick-arrow slick-disabled" aria-disabled="true" style="display: block;"></i>
    <div aria-live="polite" class="slick-list draggable">
        <div class="slick-track" style="opacity: 1; width: 4368px; left: 0px;" role="listbox">
            <div class="slide slick-slide" itemscope="" itemtype="http://schema.org/Product" data-slick-index="9" aria-hidden="true" style="width: 172px;" tabindex="-1" role="option" aria-describedby="slick-slide19">
                <div class="overlay__container relative">
                    <a href="http://www.baopals.com:3000/products/37436993683" title="Jiuchuan Bamboo Bookshelves" tabindex="-1">
                        <img src="http://example.com" itemprop="image" alt="J" title="" class="img-responsive">
                        <span itemprop="name" class="slider--name" title="Jiuchuan Bamboo Bookshelves">example</span>
                    </a>
                </div>
                <div class="slide__caption">
                    <div class="price">
                        <span>¥xx.xx</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <span class="slick-divider right slick-arrow" style="display: block;" aria-disabled="false"></span><i class="fa fa-chevron-right slick-arrow" style="display: block;" aria-disabled="false"></i>
    <ul class="slick-dots" style="display: block;" role="tablist">
        <li class="slick-active" aria-hidden="false" role="presentation" aria-selected="true" aria-controls="navigation10" id="slick-slide10">
            <button type="button" data-role="none" role="button" aria-required="false" tabindex="0">1</button>
        </li>
        <li aria-hidden="true" role="presentation" aria-selected="false" aria-controls="navigation11" id="slick-slide11">
            <button type="button" data-role="none" role="button" aria-required="false" tabindex="0">2</button>
        </li>
        <li aria-hidden="true" role="presentation" aria-selected="false" aria-controls="navigation12" id="slick-slide12">
            <button type="button" data-role="none" role="button" aria-required="false" tabindex="0">3</button>
        </li>
        <li aria-hidden="true" role="presentation" aria-selected="false" aria-controls="navigation13" id="slick-slide13">
            <button type="button" data-role="none" role="button" aria-required="false" tabindex="0">4</button>
        </li>
    </ul>
</div>

同一页面上有4个滑块。如何将分页与幻灯片上方的正确滑块相关联而非下方?

3 个答案:

答案 0 :(得分:3)

Slick中有一个名为 appendDots 的选项,您可以在其中将点导航附加到页面中的任何元素。因此,您可以尝试在滑块上方创建一个元素,然后在Slick实例中使用此元素:

$('.responsive-slider').slick({
  nextArrow: '<span class="slick-divider right"></span><i class="fa fa-chevron-right"></i>',
  prevArrow: '<span class="slick-divider left"></span><i class="fa fa-chevron-left"></i>',
  dots: true,
  infinite: false,
  appendDots: $('element-to-append-dots-nav'),
  speed: 300,
  slidesToShow: 6,
  slidesToScroll: 6,
});

尝试它是否适合你。

答案 1 :(得分:0)

试试这个:

.slick-dots{
   bottom:5px;
}

答案 2 :(得分:0)

我能够通过以下每个循环解决这个问题,将prepend添加到我的滑块

$( ".responsive-slider" ).each(function( index ) {
  $(this).prepend( $(this).find($( ".slick-dots" )));
});