/** * @name jQuery.touchSlider * @author dohoons ( http://dohoons.com/ ) * * @version 1.1.5 * @since 201106 * * @param Object settings ȯ°æº¯¼ö ¿ÀºêÁ§Æ® * roll - ¼øȯ (default true) * flexible - À¯µ¿ ·¹À̾ƿô (default true) * resize - ¸®»çÀÌÁî »ç¿ë (default false) * view - ´ÙÁß Ä÷³ (default 1) * speed - ¾Ö´Ï¸ÞÀÌ¼Ç ¼Óµµ (default 75) * range - ³Ñ±è ÆÇÁ¤ ¹üÀ§ (default 0.15) * page - Ãʱâ ÆäÀÌÁö (default 1) * transition - CSS3 transition »ç¿ë (default true) * btn_prev - prev ¹öÆ° (jQuery Object, default null) * btn_next - next ¹öÆ° (jQuery Object, default null) * paging - page ¹öÆ° (jQuery Object, default null) * sidePage - »çÀ̵å ÆäÀÌÁö »ç¿ë (default false) * initComplete - ÃʱâÈ­ Äݹé * counter - ½½¶óÀ̵å Äݹé, Ä«¿îÅÍ * autoplay - ÀÚµ¿¿òÁ÷ÀÓ °ü·Ã ¿É¼Ç (Object) * * @example $("#target").touchSlider({ page : 2 }); */ /* global jQuery */ ;(function ($) { "use strict"; $.fn.touchSlider = function (settings) { $.fn.touchSlider.defaults = { roll : true, flexible : true, resize : false, btn_prev : null, btn_next : null, paging : null, speed : 150, view : 1, range : 0.15, page : 1, sidePage : false, transition : true, initComplete : null, counter : null, propagation : false, autoplay : { enable : false, pauseHover : true, addHoverTarget : "", interval : 3500 }, supportsCssTransitions : (function (style) { var prefixes = ['Webkit','Moz','Ms']; for(var i=0, l=prefixes.length; i < l; i++ ) { if( typeof style[prefixes[i] + 'Transition'] !== 'undefined') { return true; } } return false; })(document.createElement('div').style) }; var opts = $.extend(true, {}, $.fn.touchSlider.defaults, settings); return this.each(function () { var _this = this; $.fn.extend(this, touchSlider); this.opts = opts; this.init(); $(window).on("orientationchange resize", function () { _this.resize(_this); }); }); }; var touchSlider = { init : function () { var _this = this; this._view = this.opts.view; this._speed = this.opts.speed; this._tg = $(this); this._list = this._tg.children().children(); this._width = parseInt(this._tg.css("width")); this._item_w = parseInt(this._list.css("width")); this._len = this._list.length; this._range = this.opts.range * this._width; this._pos = []; this._start = []; this._startX = 0; this._startY = 0; this._left = 0; this._top = 0; this._drag = false; this._link = true; this._scroll = false; this._hover_tg = []; this._btn_prev = null; this._btn_next = null; this._timer = null; this._tg .off("touchstart", this.touchstart) .off("touchmove", this.touchmove) .off("touchend", this.touchend) .off("touchcancel", this.touchend) .off("dragstart", this.touchstart) .off("drag", this.touchmove) .off("dragend", this.touchend) .on("touchstart", this.touchstart) .on("touchmove", this.touchmove) .on("touchend", this.touchend) .on("touchcancel", this.touchend) .on("dragstart", this.touchstart) .on("drag", this.touchmove) .on("dragend", this.touchend); this._tg.children().css({ "width":this._width + "px", "overflow":"visible" }); if(this.opts.flexible) this._item_w = this._width / this._view; if(this.opts.roll) { if(this._len % this._view > 0) { var blank = $(document.createElement(this._list.eq(0).prop("tagName"))).hide(); var cnt = this._view - (this._len % this._view); for(var j=0; j 1 && this.opts.page <= this._len) ? (this.opts.page - 1) * this._item_w * this._view : 0; for(var i=0, len=this._len; i gap) this._left = gap; if(this._left < - gap) this._left = - gap; } if(this.opts.roll) { var tmp_pos = this._pos.slice(0).sort(function(a,b){return a-b;}), max_chk = tmp_pos[len-view], p_min = $.inArray(tmp_pos[0], this._pos), p_max = $.inArray(max_chk, this._pos), p = (this.opts.sidePage) ? 3 : 1; if(view <= 1) max_chk = len - p; if((d == 1 && tmp_pos[p-1] >= 0) || (this._drag && tmp_pos[p-1] > 0)) { for(i=0; i -1) ? spd : this._speed, gap = d * (this._item_w * this._view), list = this._list; if(btn_click) this.position(d); if(this._left === 0 || (!this.opts.roll && this.limit_chk()) ) gap = 0; for(var i=0, len = this._len; i this._range) r = 1; if(!this._drag || this._scroll) r = 0; return r; }, limit_chk : function () { var last_p = parseInt((this._len - 1) / this._view) * this._view; return ( (this._start[0] === 0 && this._left > 0) || (this._start[last_p] === 0 && this._left < 0) ); }, go_page : function (i) { var crt = ($.inArray(0, this._pos) / this._view) + 1; var cal = crt - (i + 1); while(cal !== 0) { if(cal < 0) { this.animate(-1, true); cal++; } else if(cal > 0) { this.animate(1, true); cal--; } } }, get_page : function () { return { obj : this, total : Math.ceil(this._len / this._view), current : ($.inArray(0, this._pos) / this._view) + 1 }; }, counter : function () { if($.inArray(0, this._pos) < 0) { this.init(); } this.opts.page = this.get_page().current; if(this.opts.resize) { this._tg.css({ "height" : this._list.eq(this.opts.page-1).height() + "px" }); } if(typeof(this.opts.counter) == "function") { this.opts.counter.call(this, this.get_page()); } }, autoPlay : function () { var _this = this; this._timer = setInterval(function () { if(_this.opts.autoplay.enable) { var page = _this.get_page(); if(page.current == page.total && !_this.opts.roll) { _this.go_page(0); } else { _this.animate(-1, true); } } }, this.opts.autoplay.interval); }, autoStop : function () { clearInterval(this._timer); }, autoPauseToggle : function () { if(this.opts.autoplay.enable) { this.autoStop(); this.opts.autoplay.enable = false; return "stopped"; } else { this.opts.autoplay.enable = true; this.autoPlay(); return "started"; } } }; })(jQuery);