2011-06-21 67 views
2

我使用jCarousel創建滾動內容(按照此http://sorgalla.com/projects/jcarousel/)。但是我不想使用默認的next和previous按鈕,所以我想創建2個按鈕來處理click事件。 EX:我有2個超鏈接,如下所示:調用jquery jCarousel的next和prev函數?

<script> 
jQuery(document).ready(function() { 
    // Initialise the first and second carousel by class selector. 
    // Note that they use both the same configuration options (none in this case). 
    jQuery('#scrollArea').jcarousel({ 
     scroll: 10 
     }); 
</script> 
     <a>NEXT</a> 
     <a>PREV</a> 
    <div id="scrollArea"> 
<!-- CONTENT HERE --> 
</div> 

如何將next和prev函數綁定到上面的鏈接?

回答

7

看看這個例子:

http://sorgalla.com/projects/jcarousel/examples/static_controls.html

基本上,你可以在初始化傳送帶連接功能轉盤。這是相關的片段。

function mycarousel_initCallback(carousel) { 
    jQuery('#mycarousel-next').bind('click', function() { 
     carousel.next(); 
     return false; 
    }); 

    jQuery('#mycarousel-prev').bind('click', function() { 
     carousel.prev(); 
     return false; 
    }); 
}; 
+0

就像一個魅力。非常感謝。 –

-1

$('。jcarousel-next-vertical')。click();

0

的jQuery:

jQuery(function ($) { 
    $(".jcarousellite-hr").jCarouselLite({ 
     vertical: false, 
     hoverPause: true, 
     visible: 4, 
     auto: 3000, 
     speed: 1000, 
     btnNext: ".next", 
     btnPrev: ".prev" 
    }); 
}); 

HTML:

<a class="prev" href="javascript:void(0);">Prev</a> 
<a class="next" href="javascript:void(0);">Next</a>