禁用Carousel中的下一个按钮和上一个按钮

时间:2016-05-18 10:46:07

标签: javascript jquery jquery-ui carousel

我在我的应用程序中使用jquery轮播,如

            <script type="text/javascript">
     var j = jQuery.noConflict();
     j(document).ready(function () {
         j('#pagination').jcarousel({
             wrap: 'circular'
         });
         var count = $("#pagination li").size();
         if (count < 10)
         {
             j(".jcarousel-prev").addClass("jcarousel-prev-disabled");
             j(".jcarousel-next").addClass("jcarousel-next-disabled");
         }
     });

     var prm = Sys.WebForms.PageRequestManager.getInstance();

     prm.add_endRequest(function() {
         var j = jQuery.noConflict();
         j(document).ready(function () {
             j('#pagination').jcarousel({
                 wrap: 'circular'
             });
             var count = $("#pagination li").size();
             if (count < 10) {
                 j(".jcarousel-prev").addClass("jcarousel-prev-disabled");
                 j(".jcarousel-next").addClass("jcarousel-next-disabled");
             }
         });
     });
   </script>

现在的问题是,如果li项少于10,它不会使下一个按钮和上一页按钮被禁用... 请帮忙!!!

2 个答案:

答案 0 :(得分:0)

将CSS添加到您的班级,如

.jcarousel-prev-disabled, 
.jcarousel-next-disabled {
    pointer-events: none;
    cursor: default;
    opacity: 0.6;
}

<强>更新

使用$("#pagination li").length代替$("#pagination li").size(),您的问题就会解决。

答案 1 :(得分:0)

我已经下载了jQuery carousel插件并为您创建了以下示例。下面的示例将禁用prev&amp; amp;下一个按钮。如果您想完全隐藏它们,可以使用$(".jcarousel-control-next").css('display', 'none');

   <head>
    <title>Basic carousel - jCarousel Examples</title>
    <link rel="stylesheet" type="text/css" href="../_shared/css/style.css">
    <link rel="stylesheet" type="text/css" href="jcarousel.basic.css">
    <script type="text/javascript" src="../../vendor/jquery/jquery.js"></script>
    <script type="text/javascript" src="../../dist/jquery.jcarousel.min.js"></script>
    <script type="text/javascript" src="jcarousel.basic.js"></script>
    <script type="text/javascript">
        $(function(){

            var imageCount = $("#images li").length;                    
            if(imageCount < 10){
                $(".jcarousel-control-next").css('pointer-events', 'none');
                $(".jcarousel-control-prev").css('pointer-events', 'none'); 
            }
        });
    </script>
</head>
<body>
    <div class="wrapper">
        <div class="jcarousel-wrapper">
            <div class="jcarousel">
                <ul id="images">
                    <li><img src="../_shared/img/img1.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img2.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img3.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img4.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img5.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img6.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img1.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img2.jpg" width="600" height="400" alt=""></li>
                    <li><img src="../_shared/img/img3.jpg" width="600" height="400" alt=""></li>
                </ul>
            </div>
            <a href="#" class="jcarousel-control-prev">&lsaquo;</a>
            <a href="#" class="jcarousel-control-next">&rsaquo;</a>
            <p class="jcarousel-pagination">
            </p>
        </div>
    </div>
</body>
相关问题