心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

superslide.3.0.js 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /* 2019-1-29
  2. * SuperSlide v3.0 alpha开发版
  3. * 轻松解决网站大部分特效展示问题
  4. * 详尽信息请看官网:http://www.SuperSlide2.com/
  5. *
  6. * Copyright 2011-2018, 大话主席
  7. *
  8. * 请尊重原创,保留头部版权
  9. * 在保留版权的前提下可应用于个人或商业用途
  10. * v3.0:
  11. 1、修复 mouseOverStop 和 autoPlay均为false下,点击切换按钮后会自动播放bug;
  12. 2、interTime默认值改为4000;
  13. 3、vis默认值改为"auto"
  14. 4、scroll默认值改为"auto"
  15. 5、增加参数 responsive -- 默认值ture,是否开启响应式功能
  16. 6、增加参数 responsiveFun -- 响应式回调函数
  17. 7、增加参数 responsiveFunTime -- 默认值100,单位毫秒,外框宽度改变(触发响应式)时回调函数执行间隔
  18. 8、增加参数 autoHeight -- 默认值true,自动适配内容高度,常用于移动端,effect:"left或leftLoop",vis:1,scroll:1时有效
  19. 9、增加参数 canTouch -- 默认值"auto",移动端有效;是否带触摸拖拽效果;可选"auto"|true|false;auto情况下是除了fade、fold、slideDown不带触摸,其它都带
  20. 10、重新设计"fold"的实现方式,不再需要计算宽高,现在可以自适应高度
  21. 11、新增外置方法:
  22. play() -- 播放
  23. pause() -- 暂停
  24. prev() -- 上一页
  25. next() -- 下一页
  26. goTo(int) -- 跳到第int页
  27. refresh() -- 刷新效果
  28. reset() -- 重置效果
  29. getIndex() -- 获取当前页码
  30. getPages() -- 获取总页数
  31. clearStyle() -- 清除插件加入的style
  32. destroyInter() -- 销毁setInterval和setTimeout
  33. destroyEvents() -- 销毁事件绑定
  34. destroy() -- 销毁插件(clearStyle() + destroyInter() + destroyEvents())
  35. 使用方式:
  36. 执行slide后会返回superslide对象集合;
  37. 例如:
  38. var ss = $(".slider").slide({ .... });
  39. 现在想设置第二个".slider"暂停,执行代码为: ss[1].pause();
  40. */
  41. (function ($, win) {
  42. $.fn.slide = function (options) {
  43. $.fn.slide.defaults = {
  44. type: "slide",
  45. effect: "fade",
  46. autoPlay: false,
  47. delayTime: 500,
  48. interTime: 4000,
  49. triggerTime: 150,
  50. defaultIndex: 0,
  51. titCell: ".hd li",
  52. mainCell: ".bd",
  53. targetCell: null,
  54. trigger: "mouseover",
  55. scroll: "auto",
  56. vis: "auto",
  57. titOnClassName: "on",
  58. autoPage: false,
  59. prevCell: ".prev",
  60. nextCell: ".next",
  61. pageStateCell: ".pageState",
  62. opp: false,
  63. pnLoop: true,
  64. easing: "swing",
  65. startFun: null,
  66. endFun: null,
  67. switchLoad: null,
  68. playStateCell: ".playState",
  69. mouseOverStop: true,
  70. defaultPlay: true,
  71. returnDefault: false,
  72. responsive: true,
  73. responsiveFun: null,
  74. responsiveFunTime: 100,
  75. autoHeight: true,
  76. canTouch: "auto"
  77. };
  78. var ary = [];
  79. var createObj = function (opts, slider) {
  80. var _this = this;
  81. var effect = opts.effect;
  82. var prevBtn = $(opts.prevCell, slider);
  83. var nextBtn = $(opts.nextCell, slider);
  84. var pageState = $(opts.pageStateCell, slider);
  85. var playState = $(opts.playStateCell, slider);
  86. var navObj = $(opts.titCell, slider); //导航子元素结合
  87. var navObjSize = navObj.length;
  88. var conBox = $(opts.mainCell, slider); //内容元素父层对象
  89. var conBoxSize = conBox.children().length;
  90. var sLoad = opts.switchLoad;
  91. var tarObj = $(opts.targetCell, slider);
  92. /*字符串转换*/
  93. var index = parseInt(opts.defaultIndex);
  94. var delayTime = parseInt(opts.delayTime);
  95. var interTime = parseInt(opts.interTime);
  96. var triggerTime = parseInt(opts.triggerTime);
  97. var scroll = isNaN(opts.scroll) ? "auto" : parseInt(opts.scroll);
  98. var vis = isNaN(opts.vis) ? "auto" : parseInt(opts.vis);
  99. var autoPlay = (opts.autoPlay == "false" || opts.autoPlay == false) ? false : true;
  100. var opp = (opts.opp == "false" || opts.opp == false) ? false : true;
  101. var autoPage = (opts.autoPage == "false" || opts.autoPage == false) ? false : true;
  102. var pnLoop = (opts.pnLoop == "false" || opts.pnLoop == false) ? false : true;
  103. var mouseOverStop = (opts.mouseOverStop == "false" || opts.mouseOverStop == false) ? false : true;
  104. var defaultPlay = (opts.defaultPlay == "false" || opts.defaultPlay == false) ? false : true;
  105. var returnDefault = (opts.returnDefault == "false" || opts.returnDefault == false) ? false : true;
  106. var canTouch = opts.canTouch;
  107. //触摸相关
  108. var supportTouch = !!("ontouchstart" in window || window.navigator.msMaxTouchPoints);
  109. if( canTouch=="auto" ){
  110. if ( ("left leftLoop leftMarquee top topLoop topMarquee").indexOf(effect) != -1 ) {
  111. canTouch=true;
  112. }else{
  113. canTouch=false;
  114. }
  115. }else{
  116. canTouch = (opts.canTouch == "false" || opts.canTouch == false) ? false : true;
  117. }
  118. canTouch = (canTouch && supportTouch)?true:false;
  119. var touchStart = supportTouch ? 'touchstart' : 'touchstart';
  120. var touchMove = supportTouch ? 'touchmove' : 'touchmove';
  121. var touchEnd = supportTouch ? 'touchend' : 'touchend';
  122. // var touchStart = supportTouch ? 'touchstart' : 'mousedown';
  123. // var touchMove = supportTouch ? 'touchmove' : 'mousemove';
  124. // var touchEnd = supportTouch ? 'touchend' : 'mouseup';
  125. //内部使用变量
  126. var slideH = 0;
  127. var slideW = 0;
  128. var selfW = 0;
  129. var selfH = 0;
  130. var easing = opts.easing;
  131. var inter = null; //autoPlay-setInterval
  132. var titST = null; //titCell-setTimeout
  133. var rtnST = null; //返回默认-setTimeout
  134. var pnST = null; //前后按钮长安-setTimeout
  135. var resizeST = null; //win响应式-setTimeout
  136. var titOn = opts.titOnClassName;
  137. var onIndex = navObj.index(slider.find("." + titOn));
  138. var oldIndex = index = onIndex == -1 ? index : onIndex;
  139. var defaultIndex = index;
  140. var scrollNum = 0;
  141. var _ind = index;
  142. var cloneNum = 0;
  143. var _tar;
  144. var isMarq = effect == "leftMarquee" || effect == "topMarquee" ? true : false;
  145. var isLeftEffectForTouch = ("left leftLoop leftMarquee fade fold").indexOf(effect) == -1?false:true;
  146. var isTopEffectForTouch = ("top topLoop topMarquee fade fold").indexOf(effect) == -1?false:true;
  147. var isLeftEffect = ("left leftLoop leftMarquee").indexOf(effect) == -1?false:true;
  148. var isTopEffect = ("top topLoop topMarquee").indexOf(effect) == -1?false:true;
  149. var conBoxParWidth = conBox.parent().width();
  150. var conBoxParHeight = conBox.parent().height();
  151. var responsiveCallBack = function () {
  152. if ($.isFunction(opts.responsiveFun)) {
  153. opts.responsiveFun(index, navObjSize, slider, $(opts.titCell, slider), conBox, tarObj, prevBtn, nextBtn)
  154. }
  155. };
  156. var startCallBack = function () {
  157. if ($.isFunction(opts.startFun)) {
  158. opts.startFun(index, navObjSize, slider, $(opts.titCell, slider), conBox, tarObj, prevBtn, nextBtn)
  159. }
  160. };
  161. var endCallBack = function () {
  162. if ($.isFunction(opts.endFun)) {
  163. opts.endFun(index, navObjSize, slider, $(opts.titCell, slider), conBox, tarObj, prevBtn, nextBtn)
  164. }
  165. };
  166. var resetOn = function () {
  167. navObj.removeClass(titOn);
  168. if (defaultPlay) {
  169. navObj.eq(defaultIndex).addClass(titOn)
  170. }
  171. };
  172. //绑定titCell事件
  173. var titCellEvent = function (o) {
  174. if (opts.trigger == "mouseover") {
  175. o.hover(function () {
  176. var hoverInd = o.index(this);
  177. titST = setTimeout(function () {
  178. index = hoverInd;
  179. doPlay();
  180. resetInter();
  181. }, opts.triggerTime);
  182. }, function () { clearTimeout(titST) });
  183. } else {
  184. o.click(function () {
  185. index = o.index(this);
  186. doPlay();
  187. resetInter();
  188. })
  189. }
  190. };
  191. //单独处理菜单效果
  192. if (opts.type == "menu") {
  193. if (defaultPlay) {
  194. navObj.removeClass(titOn).eq(index).addClass(titOn);
  195. }
  196. navObj.hover(
  197. function () {
  198. _tar = $(this).find(opts.targetCell);
  199. var hoverInd = navObj.index($(this));
  200. titST = setTimeout(function () {
  201. index = hoverInd;
  202. navObj.removeClass(titOn).eq(index).addClass(titOn);
  203. startCallBack();
  204. switch (effect) {
  205. case "fade":
  206. _tar.stop(true, true).animate({ opacity: "show" }, delayTime, easing, endCallBack);
  207. break;
  208. case "slideDown":
  209. _tar.stop(true, true).animate({ height: "show" }, delayTime, easing, endCallBack);
  210. break;
  211. }
  212. }, opts.triggerTime);
  213. }, function () {
  214. clearTimeout(titST);
  215. switch (effect) {
  216. case "fade":
  217. _tar.animate({ opacity: "hide" }, delayTime, easing);
  218. break;
  219. case "slideDown":
  220. _tar.animate({ height: "hide" }, delayTime, easing);
  221. break;
  222. }
  223. }
  224. );
  225. if (returnDefault) {
  226. slider.hover(function () { clearTimeout(rtnST); }, function () { rtnST = setTimeout(resetOn, delayTime); });
  227. }
  228. return;
  229. }
  230. //切换加载
  231. var doSwitchLoad = function (objs) {
  232. var changeImg = function (t) {
  233. for (var i = t; i < (vis + t); i++) {
  234. objs.eq(i).find("img[" + sLoad + "]").each(function () {
  235. var _t = $(this);
  236. _t.attr("src", _t.attr(sLoad));
  237. if (conBox.find(".clone")[0]) { //如果存在.clone
  238. var chir = conBox.children();
  239. for (var j = 0; j < chir.length; j++) {
  240. chir.eq(j).find("img[" + sLoad + "]").each(function () {
  241. if ($(this).attr(sLoad) == _t.attr("src")) {
  242. $(this).attr("src", $(this).attr(sLoad));
  243. }
  244. });
  245. }
  246. }
  247. });
  248. }
  249. };
  250. switch (effect) {
  251. case "fade":
  252. case "fold":
  253. case "top":
  254. case "left":
  255. case "slideDown":
  256. changeImg(index * scroll);
  257. break;
  258. case "leftLoop":
  259. case "topLoop":
  260. changeImg(cloneNum + scrollNum(_ind));
  261. break;
  262. case "leftMarquee":
  263. case "topMarquee":
  264. var curS = effect == "leftMarquee" ? conBox.css("left").replace("px", "") : conBox.css("top").replace("px", "");
  265. var slideT = effect == "leftMarquee" ? slideW : slideH;
  266. var mNum = cloneNum;
  267. if (curS % slideT != 0) {
  268. var curP = Math.abs(curS / slideT ^ 0);
  269. if (index == 1) {
  270. mNum = cloneNum + curP
  271. } else {
  272. mNum = cloneNum + curP - 1
  273. }
  274. }
  275. changeImg(mNum);
  276. break;
  277. }
  278. }; //doSwitchLoad end
  279. //初始化
  280. var setInit = function () {
  281. var tempIndex = index;
  282. if (true) {}
  283. selfW = 0;
  284. selfH = 0;
  285. conBox.children().each(function () { //取最大值
  286. if ($(this).width() > selfW) {
  287. selfW = $(this).width();
  288. slideW = $(this).outerWidth(true);
  289. }
  290. if ($(this).height() > selfH) {
  291. selfH = $(this).height();
  292. slideH = $(this).outerHeight(true);
  293. }
  294. });
  295. if (opts.vis == "auto") {
  296. if(isTopEffect){
  297. vis = parseInt(conBoxParHeight / slideH);
  298. }else{
  299. vis = parseInt(conBoxParWidth / slideW);
  300. }
  301. vis = vis==0?1:vis;
  302. }
  303. if (opts.scroll == "auto") {
  304. scroll = vis
  305. }
  306. cloneNum = conBoxSize >= vis ? (conBoxSize % scroll != 0 ? conBoxSize % scroll : scroll) : 0;
  307. //处理分页
  308. if (navObjSize == 0) {
  309. navObjSize = conBoxSize;
  310. }
  311. //只有左右按钮
  312. if (isMarq) {
  313. navObjSize = 2;
  314. tempIndex = 0;
  315. }
  316. if (autoPage) {
  317. if (conBoxSize >= vis) {
  318. if (effect == "leftLoop" || effect == "topLoop") {
  319. navObjSize = conBoxSize % scroll != 0 ? (conBoxSize / scroll ^ 0) + 1 : conBoxSize / scroll;
  320. }
  321. //else if (isMarq){ navObjSize=2 }
  322. else {
  323. var tempS = conBoxSize - vis;
  324. navObjSize = 1 + parseInt(tempS % scroll != 0 ? (tempS / scroll + 1) : (tempS / scroll));
  325. if (navObjSize <= 0) {
  326. navObjSize = 1;
  327. }
  328. }
  329. } else {
  330. navObjSize = 1
  331. }
  332. $(opts.titCell, slider).empty();
  333. var str = "";
  334. if (opts.autoPage == true || opts.autoPage == "true") {
  335. for (var i = 0; i < navObjSize; i++) {
  336. str += "<li>" + (i + 1) + "</li>"
  337. }
  338. } else {
  339. for (var i = 0; i < navObjSize; i++) {
  340. str += opts.autoPage.replace("$", (i + 1))
  341. }
  342. }
  343. $(opts.titCell, slider).html(str);
  344. navObj = $(opts.titCell, slider).children(); //重置导航子元素对象
  345. navObj.eq(index).addClass(titOn);
  346. titCellEvent(navObj);
  347. }
  348. if (conBoxSize >= vis) { //当内容个数少于可视个数,不执行效果。
  349. //console.log(vis+"|"+cloneNum);
  350. var cloneEle = function () {
  351. var _chr = conBox.children();
  352. for (var i = 0; i < vis; i++) {
  353. _chr.eq(i).clone().addClass("clone").appendTo(conBox);
  354. }
  355. for (var i = 0; i < cloneNum; i++) {
  356. _chr.eq(conBoxSize - i - 1).clone().addClass("clone").prependTo(conBox);
  357. }
  358. };
  359. switch (effect) {
  360. case "fold":
  361. conBox.css({ "overflow": "hidden" }).children().css({ "width": "100%", "float": "left", "marginRight": "-100%", "display": "none" });
  362. break;
  363. case "top":
  364. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:' + vis * slideH + 'px"></div>').css({ "top": -(tempIndex * scroll) * slideH, "position": "relative", "padding": "0", "margin": "0" }).children().css({ "height": selfH });
  365. break;
  366. case "left":
  367. var visScope = isNaN(opts.vis) ? opts.vis : vis * slideW + 'px';
  368. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:' + visScope + '"></div>');
  369. conBox.css({ "width": conBoxSize * slideW, "left": -(tempIndex * scroll) * slideW, "position": "relative", "overflow": "hidden", "padding": "0", "margin": "0" }).children().css({ "float": "left", "width": selfW });
  370. break;
  371. case "leftLoop":
  372. case "leftMarquee":
  373. cloneEle();
  374. var visScope = isNaN(opts.vis) ? "100%" : vis * slideW + 'px';
  375. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:' + visScope + '"></div>');
  376. conBox.css({ "width": (conBoxSize + vis + 1 + cloneNum) * slideW, "position": "relative", "overflow": "hidden", "padding": "0", "margin": "0", "left": -(cloneNum + tempIndex * scroll) * slideW }).children().css({ "float": "left", "width": selfW });
  377. break;
  378. case "topLoop":
  379. case "topMarquee":
  380. cloneEle();
  381. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:' + vis * slideH + 'px"></div>').css({ "height": (conBoxSize + vis + cloneNum) * slideH, "position": "relative", "padding": "0", "margin": "0", "top": -(cloneNum + tempIndex * scroll) * slideH }).children().css({ "height": selfH });
  382. break;
  383. }
  384. }
  385. //针对leftLoop、topLoop的滚动个数
  386. scrollNum = function (ind) {
  387. var _tempCs = ind * scroll;
  388. if (ind == navObjSize) {
  389. _tempCs = conBoxSize;
  390. } else if (ind == -1 && conBoxSize % scroll != 0) {
  391. _tempCs = -conBoxSize % scroll;
  392. }
  393. return _tempCs;
  394. };
  395. //pageState.html( "<span>"+(index+1)+"</span>/"+navObjSize);
  396. }; //setInit End
  397. setInit();
  398. responsiveCallBack();
  399. //效果函数
  400. var doPlay = function (_setInit) {
  401. // 当前页状态不触发效果
  402. if (defaultPlay && oldIndex == index && !_setInit && !isMarq) {
  403. return;
  404. }
  405. //处理页码
  406. if (isMarq) {
  407. if (index >= 1) {
  408. index = 1;
  409. } else if (index <= 0) {
  410. index = 0;
  411. }
  412. } else {
  413. _ind = index;
  414. if (index >= navObjSize) {
  415. index = 0;
  416. } else if (index < 0) {
  417. index = navObjSize - 1;
  418. }
  419. }
  420. //处理切换加载
  421. if (sLoad != null) {
  422. doSwitchLoad(conBox.children())
  423. }
  424. startCallBack();
  425. //处理targetCell
  426. if (tarObj[0]) {
  427. _tar = tarObj.eq(index);
  428. if (sLoad != null) {
  429. doSwitchLoad(tarObj)
  430. }
  431. if (effect == "slideDown") {
  432. tarObj.not(_tar).stop(true, true).slideUp(delayTime);
  433. _tar.slideDown(delayTime, easing, function () {
  434. if (!conBox[0]) {
  435. endCallBack()
  436. }
  437. });
  438. } else {
  439. tarObj.not(_tar).stop(true, true).hide();
  440. _tar.animate({ opacity: "show" }, delayTime, function () {
  441. if (!conBox[0]) {
  442. endCallBack()
  443. }
  444. });
  445. }
  446. }
  447. if (conBoxSize >= vis) { //当内容个数少于可视个数,不执行效果。
  448. switch (effect) {
  449. case "fade":
  450. conBox.children().stop(true, true).eq(index).animate({ opacity: "show" }, delayTime, easing, function () { endCallBack() }).siblings().hide();
  451. break;
  452. case "fold":
  453. conBox.children().stop(true, true).eq(index).animate({ opacity: "show" }, delayTime, easing, function () { endCallBack() }).siblings().animate({ opacity: "hide" }, delayTime, easing);
  454. break;
  455. case "top":
  456. conBox.stop(true, false).animate({ "top": -index * scroll * slideH }, delayTime, easing, function () { endCallBack() });
  457. break;
  458. case "left":
  459. conBox.stop(true, false).animate({ "left": -index * scroll * slideW }, delayTime, easing, function () { endCallBack() });
  460. break;
  461. case "leftLoop":
  462. var __ind = _ind;
  463. conBox.stop(true, true).animate({ "left": -(scrollNum(_ind) + cloneNum) * slideW }, delayTime, easing, function () {
  464. if (__ind <= -1) {
  465. conBox.css("left", -(cloneNum + (navObjSize - 1) * scroll) * slideW);
  466. } else if (__ind >= navObjSize) {
  467. conBox.css("left", -cloneNum * slideW);
  468. }
  469. endCallBack();
  470. });
  471. break; //leftLoop end
  472. case "topLoop":
  473. var __ind = _ind;
  474. conBox.stop(true, true).animate({ "top": -(scrollNum(_ind) + cloneNum) * slideH }, delayTime, easing, function () {
  475. if (__ind <= -1) {
  476. conBox.css("top", -(cloneNum + (navObjSize - 1) * scroll) * slideH);
  477. } else if (__ind >= navObjSize) {
  478. conBox.css("top", -cloneNum * slideH);
  479. }
  480. endCallBack();
  481. });
  482. break; //topLoop end
  483. case "leftMarquee":
  484. var tempLeft = conBox.css("left").replace("px", "");
  485. if (index == 0) {
  486. conBox.animate({ "left": ++tempLeft }, 0, function () {
  487. if (conBox.css("left").replace("px", "") >= 0) {
  488. conBox.css("left", -conBoxSize * slideW)
  489. }
  490. });
  491. } else {
  492. conBox.animate({ "left": --tempLeft }, 0, function () {
  493. if (conBox.css("left").replace("px", "") <= -(conBoxSize + cloneNum) * slideW) {
  494. conBox.css("left", -cloneNum * slideW)
  495. }
  496. });
  497. }
  498. break; // leftMarquee end
  499. case "topMarquee":
  500. var tempTop = conBox.css("top").replace("px", "");
  501. if (index == 0) {
  502. conBox.animate({ "top": ++tempTop }, 0, function () {
  503. if (conBox.css("top").replace("px", "") >= 0) {
  504. conBox.css("top", -conBoxSize * slideH)
  505. }
  506. });
  507. } else {
  508. conBox.animate({ "top": --tempTop }, 0, function () {
  509. if (conBox.css("top").replace("px", "") <= -(conBoxSize + cloneNum) * slideH) {
  510. conBox.css("top", -cloneNum * slideH)
  511. }
  512. });
  513. }
  514. break; // topMarquee end
  515. } //switch end
  516. }
  517. navObj.removeClass(titOn).eq(index).addClass(titOn);
  518. oldIndex = index;
  519. if (!pnLoop) { //pnLoop控制前后按钮是否继续循环
  520. nextBtn.removeClass("nextStop");
  521. prevBtn.removeClass("prevStop");
  522. if (index == 0) {
  523. prevBtn.addClass("prevStop");
  524. }
  525. if (index == navObjSize - 1) {
  526. nextBtn.addClass("nextStop");
  527. }
  528. }
  529. pageState.html("<span>" + (index + 1) + "</span>/" + navObjSize);
  530. // 自动适配高度
  531. if (opts.autoHeight && (effect == "left" || effect == "leftLoop") && vis == 1 && scroll == 1) {
  532. var curItem = conBox.children().not(conBox.find(".clone")).eq(index);
  533. var pic = curItem.find("img");
  534. var picCount = pic.length;
  535. if (picCount <= 0) {
  536. conBox.height(curItem.outerHeight());
  537. return;
  538. }
  539. pic.each(function () { //存在图片时监测图片高度
  540. var img = $(this);
  541. var imgInt = setInterval(function () {
  542. if (img.height() > 0) {
  543. clearInterval(imgInt);
  544. picCount--;
  545. if (picCount <= 0) {
  546. conBox.height(curItem.outerHeight());
  547. }
  548. }
  549. }, 50);
  550. });
  551. }
  552. }; // doPlay end
  553. //初始化执行
  554. if (defaultPlay) {
  555. doPlay(true);
  556. }
  557. //返回默认状态
  558. if (returnDefault) {
  559. slider.hover(function () { clearTimeout(rtnST) }, function () {
  560. rtnST = setTimeout(function () {
  561. index = defaultIndex;
  562. if (defaultPlay) {
  563. doPlay();
  564. } else {
  565. if (effect == "slideDown") {
  566. _tar.slideUp(delayTime, resetOn);
  567. } else {
  568. _tar.animate({ opacity: "hide" }, delayTime, resetOn);
  569. }
  570. }
  571. oldIndex = index;
  572. }, 300);
  573. });
  574. }
  575. ///自动播放函数
  576. var setInter = function (time) {
  577. inter = setInterval(function () {
  578. opp ? index-- : index++;
  579. doPlay();
  580. }, !!time ? time : interTime);
  581. };
  582. var setMarInter = function (time) { inter = setInterval(doPlay, !!time ? time : interTime); };
  583. // 处理mouseOverStop
  584. var resetInter = function () {
  585. if (!mouseOverStop && autoPlay && !playState.hasClass("pauseState")) {
  586. clearInterval(inter);
  587. setInter();
  588. }
  589. }; /* 修复 mouseOverStop 和 autoPlay均为false下,点击切换按钮后会自动播放bug */
  590. // 前后按钮函数
  591. var nextFun = function () {
  592. if (pnLoop || index != navObjSize - 1) {
  593. index++;
  594. doPlay();
  595. if (!isMarq) {
  596. resetInter();
  597. }
  598. }
  599. };
  600. var prevFun = function () {
  601. if (pnLoop || index != 0) {
  602. index--;
  603. doPlay();
  604. if (!isMarq) {
  605. resetInter();
  606. }
  607. }
  608. };
  609. //处理playState
  610. var playStateFun = function () {
  611. autoPlay=true;
  612. clearInterval(inter);
  613. playState.removeClass("pauseState");
  614. isMarq ? setMarInter() : setInter();
  615. };
  616. var pauseStateFun = function () {
  617. autoPlay=false;
  618. clearInterval(inter);
  619. playState.addClass("pauseState");
  620. };
  621. //初始化自动播放
  622. var setAutoPlay = function(){
  623. if (autoPlay) {
  624. if (isMarq) {
  625. opp ? index-- : index++;
  626. setMarInter();
  627. if (mouseOverStop) {
  628. conBox.hover(pauseStateFun, playStateFun);
  629. }
  630. } else {
  631. setInter();
  632. if (mouseOverStop) {
  633. slider.hover(pauseStateFun, playStateFun);
  634. }
  635. }
  636. } else {
  637. if (isMarq) {
  638. opp ? index-- : index++;
  639. }
  640. playState.addClass("pauseState");
  641. }
  642. }
  643. setAutoPlay();
  644. //绑定事件
  645. var setTrigger = function () {
  646. playState.click(function () { playState.hasClass("pauseState") ? playStateFun() : pauseStateFun() });
  647. titCellEvent(navObj);
  648. //前后按钮事件
  649. if (isMarq) {
  650. nextBtn.mousedown(nextFun);
  651. prevBtn.mousedown(prevFun);
  652. //前后按钮长按10倍加速
  653. if (pnLoop) {
  654. var marDown = function () {
  655. pnST = setTimeout(function () {
  656. clearInterval(inter);
  657. setMarInter(interTime / 10 ^ 0)
  658. }, 150)
  659. };
  660. var marUp = function () {
  661. clearTimeout(pnST);
  662. clearInterval(inter);
  663. setMarInter()
  664. };
  665. nextBtn.mousedown(marDown);
  666. nextBtn.mouseup(marUp);
  667. prevBtn.mousedown(marDown);
  668. prevBtn.mouseup(marUp);
  669. }
  670. //前后按钮mouseover事件
  671. if (opts.trigger == "mouseover") {
  672. nextBtn.hover(nextFun, function () {});
  673. prevBtn.hover(prevFun, function () {});
  674. }
  675. } else {
  676. nextBtn.click(nextFun);
  677. prevBtn.click(prevFun);
  678. }
  679. //触摸事件
  680. if( canTouch ){
  681. conBox.on(touchStart, function (e) {
  682. conBox.stop(1, 1);
  683. clearInterval(inter);
  684. conBox.find("a").click(function (e) { e.preventDefault() });
  685. e = supportTouch ? e.originalEvent.targetTouches[0] : (e || window.event);
  686. var distX,
  687. distY,
  688. oX,
  689. oY,
  690. oL,
  691. oT;
  692. var _this = $(this);
  693. oL = this.offsetLeft;
  694. oT = this.offsetTop;
  695. oX = e.pageX;
  696. oY = e.pageY;
  697. var scrollY = false;
  698. $(this).on(touchMove, function (ev) {
  699. e = supportTouch ? ev.originalEvent.targetTouches[0] : (ev || window.event);
  700. distX = e.pageX - oX;
  701. distY = e.pageY - oY;
  702. scrollY = Math.abs(distX) < Math.abs(distY)?true:false;
  703. if (!scrollY && isLeftEffectForTouch ) {
  704. ev.preventDefault();
  705. if (effect == "left" && ((index == 0 && distX > 0) || (index >= navObjSize - 1 && distX < 0))) {
  706. distX = distX * 0.4
  707. }
  708. if(effect != "fade" && effect != "fold"){
  709. _this.css({ "left": oL + distX + "px" });
  710. }
  711. }else if( scrollY && isTopEffectForTouch ){
  712. ev.preventDefault();
  713. if (effect == "top" && ((index == 0 && distY > 0) || (index >= navObjSize - 1 && distY < 0))) {
  714. distY = distY * 0.4
  715. }
  716. if(effect != "fade" && effect != "fold"){
  717. _this.css({ "top": oT + distY + "px" });
  718. }
  719. }
  720. });
  721. $(this).on(touchEnd, function (e) {
  722. if (!distX) {
  723. conBox.find("a").off("click")
  724. }else if (!scrollY && isLeftEffectForTouch ) {
  725. if (Math.abs(distX) > slideW / 10) {
  726. distX > 0 ? index-- : index++;
  727. if (effect == "left") {
  728. index = index < 0 ? 0 : index;
  729. index = index >= navObjSize ? navObjSize - 1 : index;
  730. }
  731. }
  732. doPlay(true);
  733. }else if( scrollY && isTopEffectForTouch ){
  734. if (Math.abs(distY) > slideH / 10) {
  735. distY > 0 ? index-- : index++;
  736. if (effect == "top") {
  737. index = index < 0 ? 0 : index;
  738. index = index >= navObjSize ? navObjSize - 1 : index;
  739. }
  740. }
  741. doPlay(true);
  742. }
  743. clearInterval(inter);
  744. playState.removeClass("pauseState");
  745. if(autoPlay){ isMarq ? setMarInter() : setInter(); }
  746. conBox.off(touchMove);
  747. conBox.off(touchEnd);
  748. });
  749. });
  750. }
  751. };
  752. setTrigger();
  753. // 为检测设备尺寸变化,清除一些附加样色和元素
  754. var clear = function () {
  755. conBox.stop(true, true);
  756. if (conBox.parent().hasClass("tempWrap")) {
  757. conBox.unwrap("tempWrap")
  758. };
  759. conBox.find(".clone").remove();
  760. if(isLeftEffect){
  761. conBox.children().css({ "width": "", "float": "" });
  762. conBox.css({ "width": "", "left": 0 });
  763. }else if(isTopEffect){
  764. conBox.children().css({ "height": "" });
  765. conBox.css({ "height": "", "top": 0 });
  766. }
  767. };
  768. //检测设备尺寸变化
  769. var setResponsive = function(){
  770. if (opts.responsive) {
  771. var _vis;
  772. var _conBoxParWidth;
  773. var _conBoxParHeight;
  774. var orientationChange = function () {
  775. responsiveCallBack();
  776. _conBoxParWidth = conBox.parent().width();
  777. _conBoxParHeight = conBox.parent().height();
  778. if ( isLeftEffect && _conBoxParWidth != conBoxParWidth) { //外层宽度有变化才执行
  779. conBoxParWidth = _conBoxParWidth;
  780. //处理sLoad
  781. /*
  782. _vis = parseInt( conBox.parent().width() / slideW );
  783. vis = _vis;
  784. if( opts.scroll=="auto" ){ scroll = vis }*/
  785. clear();
  786. setInit();
  787. doPlay(true);
  788. }
  789. else if ( isTopEffect && _conBoxParHeight != conBoxParHeight) { //外层高度有变化才执行
  790. conBoxParHeight = _conBoxParHeight;
  791. clear();
  792. setInit();
  793. doPlay(true);
  794. }
  795. };
  796. $(win).resize(function () {
  797. if (resizeST) {
  798. clearTimeout(resizeST);
  799. }
  800. resizeST = setTimeout(orientationChange, opts.responsiveFunTime);
  801. });
  802. }
  803. }
  804. setResponsive();
  805. /*-- 外置API --*/
  806. //清除所有附加元素和样色
  807. this.clearStyle = function () {
  808. if (conBox.parent().hasClass("tempWrap")) {
  809. conBox.unwrap("tempWrap")
  810. };
  811. conBox.find(".clone").remove();
  812. conBox.children().removeAttr("style");
  813. conBox.removeAttr("style");
  814. };
  815. //销毁setInterval和setTimeout
  816. this.destroyInter = function () {
  817. clearInterval(inter);
  818. clearTimeout(rtnST);
  819. clearTimeout(titST);
  820. clearTimeout(pnST);
  821. //clearTimeout(resizeST);
  822. };
  823. //销毁事件绑定
  824. this.destroyEvents = function () {
  825. nextBtn.off();
  826. prevBtn.off();
  827. conBox.off();
  828. slider.off();
  829. navObj.off();
  830. //$(win).off();
  831. };
  832. //销毁插件
  833. this.destroy = function () {
  834. this.destroyEvents();
  835. this.destroyInter();
  836. this.clearStyle();
  837. };
  838. //刷新
  839. this.refresh = function () {
  840. this.destroy();
  841. setInit();
  842. setTrigger();
  843. doPlay(true);
  844. setAutoPlay();
  845. };
  846. //重置(待完善)
  847. this.reset = function () {
  848. index = parseInt(opts.defaultIndex);
  849. scroll = isNaN(opts.scroll) ? "auto" : parseInt(opts.scroll);
  850. vis = isNaN(opts.vis) ? "auto" : parseInt(opts.vis);
  851. autoPlay = (opts.autoPlay == "false" || opts.autoPlay == false) ? false : true;
  852. navObjSize = navObj.length;
  853. conBoxSize = conBox.children().length;
  854. this.refresh();
  855. };
  856. //获取当前索引/页码
  857. this.getIndex = function () { return index };
  858. //获取总页数
  859. this.getPages = function(){ return navObjSize };
  860. //暂停
  861. this.pause = function () { pauseStateFun() };
  862. this.play = function () { playStateFun() };
  863. this.prev = function () { prevFun() };
  864. this.next = function () { nextFun() };
  865. this.goTo = function (i) {
  866. resetInter();
  867. if (pnLoop || i != navObjSize ) {
  868. index = i;
  869. doPlay();
  870. }
  871. };
  872. }; //createObj End
  873. this.each(function () {
  874. var o = new createObj($.extend({}, $.fn.slide.defaults, options), $(this));
  875. ary.push(o);
  876. }); //each End
  877. return ary;
  878. }; //slide End
  879. })(jQuery, window);
  880. jQuery.easing['jswing'] = jQuery.easing['swing'];
  881. jQuery.extend(jQuery.easing,
  882. {
  883. def: 'easeOutQuad',
  884. swing: function (x, t, b, c, d) { return jQuery.easing[jQuery.easing.def](x, t, b, c, d); },
  885. easeInQuad: function (x, t, b, c, d) { return c * (t /= d) * t + b; },
  886. easeOutQuad: function (x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b },
  887. easeInOutQuad: function (x, t, b, c, d) {
  888. if ((t /= d / 2) < 1) {
  889. return c / 2 * t * t + b;
  890. }
  891. return -c / 2 * ((--t) * (t - 2) - 1) + b
  892. },
  893. easeInCubic: function (x, t, b, c, d) { return c * (t /= d) * t * t + b },
  894. easeOutCubic: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b },
  895. easeInOutCubic: function (x, t, b, c, d) {
  896. if ((t /= d / 2) < 1) {
  897. return c / 2 * t * t * t + b;
  898. }
  899. return c / 2 * ((t -= 2) * t * t + 2) + b
  900. },
  901. easeInQuart: function (x, t, b, c, d) { return c * (t /= d) * t * t * t + b },
  902. easeOutQuart: function (x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b },
  903. easeInOutQuart: function (x, t, b, c, d) {
  904. if ((t /= d / 2) < 1) {
  905. return c / 2 * t * t * t * t + b;
  906. }
  907. return -c / 2 * ((t -= 2) * t * t * t - 2) + b
  908. },
  909. easeInQuint: function (x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b },
  910. easeOutQuint: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b },
  911. easeInOutQuint: function (x, t, b, c, d) {
  912. if ((t /= d / 2) < 1) {
  913. return c / 2 * t * t * t * t * t + b;
  914. }
  915. return c / 2 * ((t -= 2) * t * t * t * t + 2) + b
  916. },
  917. easeInSine: function (x, t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b },
  918. easeOutSine: function (x, t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b },
  919. easeInOutSine: function (x, t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b },
  920. easeInExpo: function (x, t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b },
  921. easeOutExpo: function (x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b },
  922. easeInOutExpo: function (x, t, b, c, d) {
  923. if (t == 0) {
  924. return b;
  925. }
  926. if (t == d) {
  927. return b + c;
  928. }
  929. if ((t /= d / 2) < 1) {
  930. return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  931. }
  932. return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b
  933. },
  934. easeInCirc: function (x, t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b },
  935. easeOutCirc: function (x, t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b },
  936. easeInOutCirc: function (x, t, b, c, d) {
  937. if ((t /= d / 2) < 1) {
  938. return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
  939. }
  940. return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b
  941. },
  942. easeInElastic: function (x, t, b, c, d) {
  943. var s = 1.70158;
  944. var p = 0;
  945. var a = c;
  946. if (t == 0) {
  947. return b;
  948. }
  949. if ((t /= d) == 1) {
  950. return b + c;
  951. }
  952. if (!p) {
  953. p = d * .3;
  954. }
  955. if (a < Math.abs(c)) {
  956. a = c;
  957. var s = p / 4;
  958. } else {
  959. var s = p / (2 * Math.PI) * Math.asin(c / a);
  960. }
  961. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
  962. },
  963. easeOutElastic: function (x, t, b, c, d) {
  964. var s = 1.70158;
  965. var p = 0;
  966. var a = c;
  967. if (t == 0) {
  968. return b;
  969. }
  970. if ((t /= d) == 1) {
  971. return b + c;
  972. }
  973. if (!p) {
  974. p = d * .3;
  975. }
  976. if (a < Math.abs(c)) {
  977. a = c;
  978. var s = p / 4;
  979. } else {
  980. var s = p / (2 * Math.PI) * Math.asin(c / a);
  981. }
  982. return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
  983. },
  984. easeInOutElastic: function (x, t, b, c, d) {
  985. var s = 1.70158;
  986. var p = 0;
  987. var a = c;
  988. if (t == 0) {
  989. return b;
  990. }
  991. if ((t /= d / 2) == 2) {
  992. return b + c;
  993. }
  994. if (!p) {
  995. p = d * (.3 * 1.5);
  996. }
  997. if (a < Math.abs(c)) {
  998. a = c;
  999. var s = p / 4;
  1000. } else {
  1001. var s = p / (2 * Math.PI) * Math.asin(c / a);
  1002. }
  1003. if (t < 1) {
  1004. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  1005. }
  1006. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b
  1007. },
  1008. easeInBack: function (x, t, b, c, d, s) {
  1009. if (s == undefined) {
  1010. s = 1.70158;
  1011. }
  1012. return c * (t /= d) * t * ((s + 1) * t - s) + b
  1013. },
  1014. easeOutBack: function (x, t, b, c, d, s) {
  1015. if (s == undefined) {
  1016. s = 1.70158;
  1017. }
  1018. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b
  1019. },
  1020. easeInOutBack: function (x, t, b, c, d, s) {
  1021. if (s == undefined) {
  1022. s = 1.70158;
  1023. }
  1024. if ((t /= d / 2) < 1) {
  1025. return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  1026. }
  1027. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b
  1028. },
  1029. easeInBounce: function (x, t, b, c, d) { return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b },
  1030. easeOutBounce: function (x, t, b, c, d) {
  1031. if ((t /= d) < (1 / 2.75)) {
  1032. return c * (7.5625 * t * t) + b;
  1033. } else if (t < (2 / 2.75)) {
  1034. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  1035. } else if (t < (2.5 / 2.75)) {
  1036. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  1037. } else {
  1038. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  1039. }
  1040. },
  1041. easeInOutBounce: function (x, t, b, c, d) {
  1042. if (t < d / 2) {
  1043. return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
  1044. }
  1045. return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  1046. }
  1047. });