/* @extends jquery v1.10.2 * @fileOverview 自動兼容PC端、移動端的圖片循環滾動插件 * @email 122452357@qq.com * @version v3.0 * @date 2016-01-05 * @remark Wang Yunhong -- The love of my life. * Copyright (c) 2015-2016 天涯淺唱, 請尊重勞動成果,若直接使用請注明出處,謝謝! * @example * $("slider").YuxiSlider(); * @parameter{ width:容器寬度, height:容器高度, control:控制按鈕,PC端可傳入控制按鈕對象,移動端無按鈕 auto:是否自動播放 默認自動(true), during:間隔時間, speed:圖片滑動速度, mousewheel:是否開啟鼠標滑輪 默認否(false), direkey:是否綁定方向鍵 默認否(false) } */ !function(a){a.fn.extend({YuxiSlider:function(b){var c={width:640,height:360,control:null,auto:!0,during:3e3,speed:800,mousewheel:!1,direkey:!1},d=a.extend(c,b);return a(this).each(function(){var b=a(this),c=a("ul",b),e=a("li",b),f=e.length,g=0,h=null,i='
';b.append(i);var j=a("p.title a",b),k=a("em.curr-num",b),l=a("em.total-num",b),m=0,n={},o={},p={mobileDevice:navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i),init:function(){if(p.style(),p.mobileDevice){var e=a(window).width(),g=d.width/d.height;d.width=e,d.height=e/g,b.css({fontSize:a(window).width()/640*1.285+"rem"})}b.add("img",b).width(d.width).height(d.height),c.width(f*d.width),p.description(),p.bindControl(),f>2&&c.prepend(a("li",c).last()).css({left:-d.width}),d.auto&&p.auto()},auto:function(){h=d.auto?setInterval(function(){p.moving(!0)},d.during):null},stop:function(){h&&clearInterval(h)},description:function(){k.text(g+1),l.text(f),j.text(e.eq(g).find("img").attr("alt")).attr("href",e.eq(g).find("a").attr("href")).width(d.width-a("span.num",b).width()-20)},bindControl:function(){if(p.mobileDevice){if(d.control&&d.control.remove(),2>=f)return;c.get(0).addEventListener("touchstart",p.touchstart,!1),c.get(0).addEventListener("touchmove",p.touchmove,!1),c.get(0).addEventListener("touchend",p.touchend,!1)}else{b.hover(function(){d.auto&&p.stop(),a(document).on("keydown",function(a){a.preventDefault(),(39===a.keyCode||40===a.keyCode)&&p.moving(!0),(37===a.keyCode||38===a.keyCode)&&p.moving(!1)})},function(){a(document).unbind(),d.auto&&p.auto()});var e=void 0!==document.mozHidden?"DOMMouseScroll":"mousewheel";d.mousewheel&&b.on(e,function(a){a.preventDefault(),a.stopPropagation();var c=a.originalEvent.wheelDelta?a.originalEvent.wheelDelta:-a.originalEvent.detail,d=b.data("timeoutId");d&&clearInterval(d),b.data("timeoutId",setTimeout(function(){p.moving(0>c?!0:!1),b.removeData("timeoutId")},100))}),d.control&&d.control.on("click",function(){p.moving(a(this).index()?!0:!1)}).hover(function(){d.auto&&p.stop()},function(){d.auto&&p.auto()})}},moving:function(b){if(1!=f){var e=0,h=!0;"boolean"==typeof b?h=b:(h=b>0?!1:!0,e=b),g=h?g>=f-1?0:g+1:0>=g?f-1:g-1,p.description(),f>2?(h?c.append(a("li",c).first()).css({left:0+e}):c.prepend(a("li",c).last()).css({left:-2*d.width+e}),c.stop().animate({left:[-d.width,"easeOutExpo"]},d.speed)):h?c.stop().animate({left:-d.width},.6*d.speed,function(){a(this).append(a("li",this).first()).css({left:0})}):c.prepend(a("li",c).last()).css({left:-d.width+e}).stop().animate({left:0},.6*d.speed)}},touchPos:function(a){for(var c,d,e,b=a.changedTouches,f={},g=0;g