圖片輪播可由容器、滑動層與指示按鈕組成。自動播放依靠計時器,手動切換則透過點擊或滑入指示器改變索引。
以下概念以 TransformView 為例:每次切換時改變索引,再移動 slider 的位置,讓目標圖片進入可視區域。

var TransformView = function (container, slider, width, count) {
this.container = document.getElementById(container);
this.slider = document.getElementById(slider);
this.width = width;
this.count = count;
this.index = 0;
};
TransformView.prototype.start = function () {
if (this.index < 0) this.index = this.count - 1;
if (this.index >= this.count) this.index = 0;
var target = -this.width * this.index;
this.slider.style.left = target + 'px';
};