当前位置: 代码迷 >> JavaScript >> JS图片轮播的有关问题
  详细解决方案

JS图片轮播的有关问题

热度:78   发布时间:2013-09-05 16:02:06.0
JS图片轮播的问题

function adjust(containerID) {
            var container = $("#" + containerID);
            var imgs = container.find("img");
            _self = this;
            _self.speed = 3;
            _self.imgs = imgs;
            _self.container = container;
            _self.width = parseInt(container.width());
            _self.length = _self.imgs.length;
            _self.imgWidth = Math.round(_self.width/_self.length);
            _self.run = function () {
                var left = Math.abs(parseInt(_self.container.css("left")));
                if (left < _self.width - _self.imgWidth) {
                    _self.container.css("left", (-left - _self.speed) + "px");
                    console.log(left);
                } else {
                    _self.container.find("img:eq(0)").appendTo(_self.container);
                    _self.container.css("left", (-left + _self.imgWidth - _self.speed) + "px");
                }
                setTimeout(function () {
                    _self.run();
                }, 33);
                }
  相关解决方案