Call next and prev function of jquery jCarousel?

2019-04-02 06:16发布

I use jCarousel for creating a scroll content (follow this http://sorgalla.com/projects/jcarousel/). However I dont want to use the default next and previous button so I want to create 2 buttons for handling the click event. EX: I have 2 hyperlinks like these:

<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>

How can I bind the next and prev functions to above links?

4条回答
狗以群分
2楼-- · 2019-04-02 06:33

Check out this example:

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

Basically, you can attach functions to the carousel in the initialization for the carousel. Here is the relevant snippet.

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

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
查看更多
Fickle 薄情
3楼-- · 2019-04-02 06:34

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

查看更多
劫难
4楼-- · 2019-04-02 06:40

You can also do

`$('.jcarousel-next').click(function() {
    $('.jcarousel').jcarousel('scroll', '+=1');
});`

Here is more info: http://sorgalla.com/jcarousel/docs/reference/usage.html

查看更多
Summer. ? 凉城
5楼-- · 2019-04-02 06:46

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>
查看更多
登录 后发表回答