如何水平自动滚动轮播(jquery)

时间:2013-09-06 14:43:50

标签: javascript jquery html css twitter-bootstrap

我有一个旋转木马,它通过点击一个按钮水平移动,但我需要它继续滚动,因为我是jquery和javascript的新手(我也请你们耐心哈哈) 我对代码感到困惑。

代码:

/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 **/
var handlePrevButtonState = function(type, args) {
    var enabling = args[0];
    var leftImage = args[1];
    if(enabling) {
        leftImage.src = "imagens/esq_ativo.jpg";    
    } else {
        leftImage.src = "imagens/esq_inativo.jpg";  
    }
};
/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the next button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: nextButtonStateHandler
 **/
var handleNextButtonState = function(type, args) {
    var enabling = args[0];
    var rightImage = args[1];
    if(enabling) {
        rightImage.src = "imagens/dir_ativo.jpg";
    } else {
        rightImage.src = "imagens/dir_inativo.jpg";
    }
};
/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'mycarousel'.) See the
 * HTML code below.
 **/
var carousel; // for ease of debugging; globals generally not a good idea
var pageLoad = function() 
{
    carousel = new YAHOO.extension.Carousel("mycarousel", 
        {
            numVisible:        9,
            animationSpeed:    0.15,
            scrollInc:         9,
            navMargin:         15,
            prevElement:     "prev-arrow",
            nextElement:     "next-arrow",
            size:              18,
            prevButtonStateHandler:   handlePrevButtonState,
            nextButtonStateHandler:   handleNextButtonState
        }
    );
};
YAHOO.util.Event.addListener(window, 'load', pageLoad);

谢谢!

1 个答案:

答案 0 :(得分:0)

启动轮播时,您需要使用间隔值设置autoPlay

示例

carousel = new YAHOO.extension.Carousel("mycarousel", 
    {
        numVisible:        9,
        animationSpeed:    0.15,
        scrollInc:         9,
        navMargin:         15,
        prevElement:     "prev-arrow",
        nextElement:     "next-arrow",
        size:              18,
        prevButtonStateHandler:   handlePrevButtonState,
        nextButtonStateHandler:   handleNextButtonState,
        autoPlay: 1000
    }

更新

要使轮播循环,您需要将wrap设置为true。

示例

carousel = new YAHOO.extension.Carousel("mycarousel", 
{
    // Your previous settings
    wrap: true
}