问题
I am encountering an issue with jCarousel whereby if a the carousel has started at the beginning and the left button is pressed the carousel doesn't scroll.
What is supposed to happen is that if the carousels first item is displayed and the left button is pressed, the carousel should circle to the end item. At the moment, this does not happen. The carousel just stops working.
This only happens when the carousel is first loaded.
Example of my code is here: http://jsfiddle.net/wquPu/2/.
Thanks.
回答1:
I don't know exactly what you are doing wrong, but if you look at the jCarousel demo pages you will find a demo of exactly what you are trying to do and it's very simple code.
http://sorgalla.com/projects/jcarousel/examples/static_auto.html
function mycarousel_initCallback(carousel)
{
// Disable autoscrolling if the user clicks the prev or next button.
carousel.buttonNext.bind('click', function() {
carousel.startAuto(0);
});
carousel.buttonPrev.bind('click', function() {
carousel.startAuto(0);
});
// Pause autoscrolling if the user moves with the cursor over the clip.
carousel.clip.hover(function() {
carousel.stopAuto();
}, function() {
carousel.startAuto();
});
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
auto: 2,
wrap: 'last',
initCallback: mycarousel_initCallback
});
});
来源:https://stackoverflow.com/questions/5441975/jcarousel-continue-scrolling-when-at-first-or-last-item-on-button-press