(function($){ $.fn.extend({ dy_scroll: function(options){ var _this = $(this); //parent _this.each(function(){ var _this = $(this); var ops = $.extend({ prev: _this.find(".prev"), //prev next: _this.find(".next"), //next list: _this.find("ul"), //list auto: false, //autplay speed: 4, //autospeed num: 1, //minlength toggle: true //isscrollx }, options) var $li = ops.list.find("li"), w = ops.list.find("li").outerwidth(true), h = ops.list.find("li").outerheight(true), len = $li.length; if(len >= ops.num){ // click if(ops.toggle){ ops.next.click(function() { w = ops.list.find("li").outerwidth(true); ops.list.animate({ "margin-left": -w }, function() { ops.list.find("li").eq(0).appendto(ops.list); ops.list.css({ "margin-left": 0 }) }) }); ops.prev.click(function() { w = ops.list.find("li").outerwidth(true); ops.list.find("li:last").prependto(ops.list); ops.list.css({ "margin-left": -w }); ops.list.animate({ "margin-left": 0 }) }); }else{ ops.next.click(function() { h = ops.list.find("li").outerheight(true); ops.list.animate({ "margin-top": -h }, function() { ops.list.find("li").eq(0).appendto(ops.list); ops.list.css({ "margin-top": 0 }) }) }); ops.prev.click(function() { h = ops.list.find("li").outerheight(true); ops.list.find("li:last").prependto(ops.list); ops.list.css({ "margin-top": -h }); ops.list.animate({ "margin-top": 0 }) }); }; // autoplay if(ops.auto) { var ad = setinterval(time, ops.speed * 1000); _this.hover(function() { clearinterval(ad) }, function() { ad = setinterval(time, ops.speed * 1000) }) }; function time(){ ops.next.click(); } // touch if("ontouchstart" in document || $(window).innerwidth() <= 1024){ var touch = 0, touchend = 0; ops.list[0].addeventlistener("touchstart", function(e){ touch = e.targettouches[0]; }); ops.list[0].addeventlistener("touchend", function(e){ touchend = e.changedtouches[0]; var totalx = math.abs(touchend.screenx - touch.screenx), totaly = math.abs(touchend.screeny - touch.screeny); if( totalx > totaly && totalx >= 100){ if(touchend.screenx - touch.screenx > 0){ ops.prev.click(); }else{ ops.next.click(); } } }); } } }) } }) }($))