光滑的滑块箭头在响应模式下表现得像幻灯片

Posted

技术标签:

【中文标题】光滑的滑块箭头在响应模式下表现得像幻灯片【英文标题】:Slick slider arrows behave as slides in resposnsive mode 【发布时间】:2015-12-15 05:04:36 【问题描述】:

我已经为我的引导项目集成了 slick carousel,并且我已经修改了 slick-theme.css 以进行一些自定义。我遇到了这个奇怪的问题,在响应模式下,滑块全部出错,幻灯片重复,箭头(它们被自定义为下一个和上一个按钮)显示为幻灯片。当我删除响应参数时,它可以正常工作。我想删除小屏幕尺寸的箭头。如果有人可以帮助我解决这个问题,那就太好了。谢谢。

PS:编辑后的 ​​slick-theme.css 文件的代码在此代码 sn-p 的 css 部分的底部。

 $(window).load(function () 
                $('.slider-main').slick(
                    arrows: true,
                    dots: false,
                    prevArrow: "<a class=\"slick-prev slider-slick-prev\">PREVIOUS</a>",
                    nextArrow: "<a class=\"slick-next slider-slick-next\">NEXT</a>",
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    responsive: [
                        
                            breakpoint: 767,
                            settings: 
                                arrows: false
                            
                        
                    ]
                );
            );
.slider > div 
    padding: 0 40px;


@media only screen and (max-width: 1200px) 
    .slider > div 
        padding: 0 10px;
    


.slider > div .slider-left 
    padding: 0 16px 0 23px;
    text-align: center;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left 
        padding: 0 5px 0 0;
    


@media only screen and (max-width: 767px) 
    .slider > div .slider-left 
        display: none;
    


.slider > div .slider-left > div 
    border-left: 1px solid #e8e8e8;
    border-right: 1px solid #e8e8e8;
    border-bottom: 1px solid #e8e8e8;
    margin-top: 13px;


.slider > div .slider-left > div > h2 
    background: #bbe3de;
    color: #ffffff;
    font-size: 21.36px;
    margin: 0;
    padding: 18px 0;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > h2 
        font-size: 19.36px;
        padding: 18px 10px;
    


.slider > div .slider-left > div > div.left-description 
    color: #afafaf;
    font-size: 25px;
    margin-top: 35px;
    line-height: 1.2;
    padding: 0 23px;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > div.left-description 
        margin-top: 5px;
        font-size: 17px;
        padding: 0 5px;
    


.slider > div .slider-left > div > div.left-info 
    color: #9d9d9d;
    font-size: 17px;
    margin-top: 28px;
    line-height: 1.2;
    padding: 0 4px;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > div.left-info 
        margin-top: 5px;
    


.slider > div .slider-left > div > div.left-location 
    color: #9d9d9d;
    font-size: 25px;
    margin-top: 2px;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > div.left-location 
        font-size: 17px;
    


.slider > div .slider-left > div > div.left-read-more 
    margin-top: 16px;
    margin-bottom: 18px;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > div.left-read-more 
        margin-top: 5px;
    


.slider > div .slider-left > div > div.left-read-more a 
    color: #ec6b9c;
    font-size: 22.29px;
    -webkit-transition: color 0.2s ease;
    -moz-transition: color 0.2s ease;
    -ms-transition: color 0.2s ease;
    -o-transition: color 0.2s ease;
    transition: color 0.2s ease;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-left > div > div.left-read-more a 
        font-size: 17px;
    


.slider > div .slider-left > div > div.left-read-more a:hover 
    color: #bbe3de;


.slider > div .slider-main 
    padding: 13px 39px 0 16px;


@media only screen and (max-width: 1200px) 
    .slider > div .slider-main 
        padding: 13px 0 0 5px;
    


.slider > div .slider-main .single-slide 
    outline: none;


.slider > div .slider-main .single-slide:hover 
    outline: none;


.slider > div .slider-main .single-slide:focus 
    outline: none;


.slider > div .slider-main .single-slide img 
    width: 100%;
    outline: none;


.slider > div .slider-main .single-slide img:hover 
    outline: none;


.slider > div .slider-main .single-slide img:focus 
    outline: none;


.slider > div .slider-main .single-slide .slide-description 
    position: absolute;
    bottom: 18px;
    right: 0;
    text-transform: uppercase;
    background: #ffffff;
    padding: 10px 21px 5px 18px;
    letter-spacing: -0.3px;
    color: #878787;
    font-size: 22.37px;


.slider > div .slider-main .single-slide .slide-description a 
    margin-left: 4px;
    letter-spacing: 0.5px;
    display: inline-block;
    color: #ec6b9c;
    font-size: 15px;
    -webkit-transition: color 0.2s ease;
    -moz-transition: color 0.2s ease;
    -ms-transition: color 0.2s ease;
    -o-transition: color 0.2s ease;
    transition: color 0.2s ease;


.slider > div .slider-main .single-slide .slide-description a:hover 
    color: #bbe3de;


.slider > div .slider-left-mobile 
    padding: 0 16px 0 23px;
    text-align: center;


.slider > div .slider-left-mobile > div 
    border-left: 1px solid #e8e8e8;
    border-right: 1px solid #e8e8e8;
    border-bottom: 1px solid #e8e8e8;
    margin-top: 13px;


.slider > div .slider-left-mobile > div > h2 
    background: #bbe3de;
    color: #ffffff;
    font-size: 21.36px;
    margin: 0;
    padding: 18px 0;


.slider > div .slider-left-mobile > div > div.left-description 
    color: #afafaf;
    font-size: 25px;
    margin-top: 35px;
    line-height: 1.2;
    padding: 0 23px;


.slider > div .slider-left-mobile > div > div.left-info 
    color: #9d9d9d;
    font-size: 17px;
    margin-top: 28px;
    line-height: 1.2;
    padding: 0 4px;


.slider > div .slider-left-mobile > div > div.left-location 
    color: #9d9d9d;
    font-size: 25px;
    margin-top: 2px;


.slider > div .slider-left-mobile > div > div.left-read-more 
    margin-top: 16px;
    margin-bottom: 18px;


.slider > div .slider-left-mobile > div > div.left-read-more a 
    color: #ec6b9c;
    font-size: 22.29px;
    -webkit-transition: color 0.2s ease;
    -moz-transition: color 0.2s ease;
    -ms-transition: color 0.2s ease;
    -o-transition: color 0.2s ease;
    transition: color 0.2s ease;


.slider > div .slider-left-mobile > div > div.left-read-more a:hover 
    color: #bbe3de;


/*slick theme customized*/
/* Arrows */
.slick-prev,
.slick-next 
    position: absolute;
    display: block;
    font-size: 16.5px;
    cursor: pointer;
    background: #ffffff;
    color: #878787;
    top: 50%;
    margin-top: -23px;
    padding: 15px 17px;
    border: none;
    outline: none;
    z-index: 1;
    -webkit-transition: color 0.2s ease;
    -moz-transition: color 0.2s ease;
    -ms-transition: color 0.2s ease;
    -o-transition: color 0.2s ease;
    transition: color 0.2s ease;


.slick-prev:hover,
.slick-next:hover 
    outline: none;
    color: #ec6b9c;


.slick-prev 
    left: 16px;


@media only screen and (max-width: 1200px) 
    .slick-prev 
        left: 5px;
    


[dir="rtl"] .slick-prev 
    left: auto;
    right: 39px;


@media only screen and (max-width: 1200px) 
    [dir="rtl"] .slick-prev 
        right: -1px;
    


.slick-next 
    right: 39px;


@media only screen and (max-width: 1200px) 
    .slick-next 
        right: -1px;
    


[dir="rtl"] .slick-next 
    left: 16px;
    right: auto;


@media only screen and (max-width: 1200px) 
    [dir="rtl"] .slick-next 
        left: 5px;
    


/* Dots */
.slick-slider 
    margin-bottom: 5px;


.slick-dots 
    position: absolute;
    bottom: -45px;
    list-style: none;
    display: block;
    text-align: center;
    padding: 0;
    width: 100%;


.slick-dots li 
    position: relative;
    display: inline-block;
    height: 20px;
    width: 20px;
    margin: 0 5px;
    padding: 0;
    cursor: pointer;


.slick-dots li button 
    border: 0;
    background: transparent;
    display: block;
    height: 20px;
    width: 20px;
    outline: none;
    line-height: 0px;
    font-size: 0px;
    color: transparent;
    padding: 5px;
    cursor: pointer;


.slick-dots li button:hover, .slick-dots li button:focus 
    outline: none;


.slick-dots li button:before 
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    font-size: 6px;
    line-height: 20px;
    text-align: center;
    -webkit-font-smoothing: antialiased;


/*# sourceMappingURL=slick-theme.css.map */

/*slick theme customized*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified javascript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.7/slick.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.7/slick.js"></script>
<div class="container-fluid">    
<div class="row slider">
                <div class="col-xs-12">
                    <div class="col-xs-12 col-sm-3 slider-left">
                        <div class="col-xs-12">
                            <h2>PARTY DECORATIORS</h2>

                            <div class="col-xs-12 left-description">
                                LOOKING for someone to come and DECORATE your NEXT PARTY?
                            </div>
                            <div class="col-xs-12 left-info">
                                We will come and
                                <br>
                                decorate your children's party
                                <br>
                                within a 50 mile radius of
                            </div>
                            <div class="col-xs-12 left-location">
                                IPSWICH
                            </div>
                            <div class="col-xs-12 left-read-more">
                                <a href="#">READ MORE</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12 col-sm-9 slider-main">
                        <div class="col-xs-12 single-slide">
                            <img src="https://placehold.it/350x150" />

                            <div class="slide-description">
                                book us to decorate your next party!
                                <a href="#">CLICK HERE</a>
                            </div>
                        </div>
                        <div class="col-xs-12 single-slide">
                            <img src="https://placehold.it/350x150" />

                            <div class="slide-description">
                                book us to decorate your next party!
                                <a href="#">CLICK HERE</a>
                            </div>
                        </div>
                        <div class="col-xs-12 single-slide">
                            <img src="https://placehold.it/350x150" />

                            <div class="slide-description">
                                book us to decorate your next party!
                                <a href="#">CLICK HERE</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
                        </div>

更新:最近的更新 1.5.9 修复了该问题。

【问题讨论】:

@Ryan 如果您仔细观察,您会发现有超过 3 张幻灯片,即使我在 html 中只添加了 3 张幻灯片。幻灯片的对齐方式都错了,滑动 3 张幻灯片后,实际上是箭头(下一个/上一个按钮)在那之后滑动。 【参考方案1】:

我遇到了同样的问题。将 slick.js 降级到旧版本(1.3.15)后,问题已修复。

【讨论】:

【参考方案2】:

哦!我现在看到了。我认为这是滑块脚本错误,因为它在滑块 div 内生成了另一个控制标签。因此,如果您只是想移除小屏幕尺寸的控件,请使用以下 css 并从滑块脚本中移除响应式属性。

@media screen and (max-width:767px)

    a.slick-arrow
    display:none !important;    
    

【讨论】:

它对我不起作用,可能是因为每次幻灯片移动后 slick 都会再次渲染箭头

以上是关于光滑的滑块箭头在响应模式下表现得像幻灯片的主要内容,如果未能解决你的问题,请参考以下文章

光滑的滑块 - 随着更多幻灯片加载到滑块中,幻灯片会缩小

我如何在光滑的滑块中只显示三张幻灯片?

javascript 光滑的滑块 - 标签 - 使幻灯片显示动态

光滑的滑块 - 当滑块进入下一帧时暂停 YouTube 剪辑

如何获得光滑的滑块以在循环中平滑过渡

在光滑的滑块内居中项目