第一次和最后一次激活时禁用左右控件

时间:2017-09-02 12:05:45

标签: javascript jquery html css frontend

如果第一个项目处于活动状态时如何禁用左控制,如果最后一个项目处于活动状态,则同样向右移动然后禁用右控制

如果我得到任何建议,我将不胜感激,有没有替代方案 谢谢

JsFiddle Here

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="carousel slide" data-ride="carousel" id="quote-carousel">
                <!-- Carousel Slides / Quotes -->
                <div class="carousel-inner text-center">
                    <!-- Quote 1 -->
                    <div class="item active">
                        <blockquote>
                            <div class="row">
                                <div class="col-sm-8 col-sm-offset-2">
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,ore et dolore magna aliqua. Ut eni !</p>
                                </div>
                            </div>
                        </blockquote>
                    </div>
                    <!-- Quote 2 -->
                    <div class="item">
                        <blockquote>
                            <div class="row">
                                <div class="col-sm-8 col-sm-offset-2">
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,ore et dolore magna aliqua. Ut eni !</p>
                                </div>
                            </div>
                        </blockquote>
                    </div>
                    <!-- Quote 3 -->
                    <div class="item">
                        <blockquote>
                            <div class="row">
                                <div class="col-sm-8 col-sm-offset-2">
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,ore et dolore magna aliqua. Ut eni !</p>
                                </div>
                            </div>
                        </blockquote>
                    </div>
                </div>
                <!-- Bottom Carousel Indicators -->
                <ol class="carousel-indicators">
                    <li data-target="#quote-carousel" data-slide-to="0" class="active"><img class="img-responsive " src="https://s3.amazonaws.com/uifaces/faces/twitter/mantia/128.jpg" alt="">
                    </li>
                    <li data-target="#quote-carousel" data-slide-to="1"><img class="img-responsive" src="https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg" alt="">
                    </li>
                    <li data-target="#quote-carousel" data-slide-to="2"><img class="img-responsive" src="https://s3.amazonaws.com/uifaces/faces/twitter/brad_frost/128.jpg" alt="">
                    </li>
                </ol>
                <!-- Carousel Buttons Next/Prev -->
               <a data-slide="prev" href="#quote-carousel" class="left carousel-control"><i class="fa fa-chevron-left"></i></a>
                <a data-slide="next" href="#quote-carousel" class="right carousel-control"><i class="fa fa-chevron-right"></i></a>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用slid.bs.carousel引导事件

来执行此操作

<强> 1。显示或隐藏控件

jQuery("#quote-carousel").on('slid.bs.carousel', function () {

    //Show or Hide left indicator 
    if($(this).find('li:first-child').hasClass('active')){
        $(this).find('.left').hide();
    }else{
        $(this).find('.left').show();
    }

    //Show or Hide right indicator 
    if($(this).find('li:last').hasClass('active')){
        $(this).find('.right').hide();
    }else{
        $(this).find('.right').show();
    }
}).trigger('slid.bs.carousel');

<强> 2。用于禁用控件

您可以使用CSS pointer-events禁用它。 请参阅此处了解完整代码align-items