carousel組件可以實現走馬燈的效果。有的時候需要實現自動輪播的功能。
查看carousel組件的api,有next()函數
Switches to the next card.
setInterval(function(){
myCrousel = Ext.ComponentQuery.query('carousel')[0];
myCrousel.next();
if (myCrousel.getActiveIndex() === myCrousel.getMaxItemIndex()) {
myCrousel.setActiveItem(0);
}
}, 3000);
其中的if判斷語句當判斷到達走馬燈最後一張時自動切換到第一張。