﻿var jq = jQuery.noConflict();
jq(function() {
    jq.fn.scrollFx = function(o) {
        return this.each(function() {
            var self = this;
            //定义变量

            self.jqul = jq("ul", this), self.jqli = jq("li", this), self.jql = self.jqli.length, self.jqw = parseInt(self.jqli.outerWidth(true)), self.jqmax_x = self.jql * self.jqw, jqautoId = self;
            //alert(jqmax_x);
            //克隆，实现无间歇滚动
            self.jqul.append(self.jqli.slice(0, 5).clone());

            //默认自动滚动
            auto();

            //自动播放方法
            function auto() {
                //定义滚动
                self.jqautoId = setInterval(showImg, 40);
            };

            function showImg() {
                //设置位移
                self.jqul = jq("ul", self);
                self.jqle = parseInt(self.jqul.css("left"));

                self.jqle > -self.jqmax_x ? self.jqle-- : self.jqle = 0;
                self.jqul.css({ left: self.jqle + "px" });
            };

            //鼠标移上去的时候清除滚动
            self.jqul.mouseover(function() {
                clearInterval(self.jqautoId);
            });

            //鼠标移开继续滚动
            self.jqul.mouseout(function() {
                auto();
            });

        });
    };
});
