TL_PC_Slider.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. (function($){
  2. $.fn.TL_PC_Slider = function(options) {
  3. return $.fn.TL_PC_Slider.defaults = {
  4. type: "TL_Display", // TL_Display 渐显 TL_Top 上下滚动 TL_Left左右 TL_Fade淡入淡出
  5. auto_play: false,
  6. timer: 500,//持续时间
  7. speed: 2500,// 运行间隔。
  8. tab: ".tab li",
  9. box: ".box",
  10. page_box: ".df_slide_page",
  11. actions: "tl_hover",//tl_hover tl_click
  12. tab_on: "df_on",
  13. page: false,//是否分页
  14. prev: ".df_prev",
  15. next: ".df_next",
  16. fun_start: null,
  17. fun_end: null
  18. },
  19. this.each(function() {
  20. var sitting = $.extend({}, $.fn.TL_PC_Slider.defaults, options),
  21. tl_type = sitting.type,
  22. tl_prev = $(sitting.prev, $(this)),
  23. tl_next = $(sitting.next, $(this)),
  24. tl_page_box = $(sitting.page_box, $(this)),
  25. tl_tab = $(sitting.tab, $(this)),
  26. tl_tab_sise = tl_tab.size(),
  27. tl_box = $(sitting.box, $(this)),
  28. tl_box_size = tl_box.children().size(),
  29. tl_index = 0,//默认项
  30. tl_timer = parseInt(sitting.timer),
  31. tl_get_speed = parseInt(sitting.speed);
  32. var tl_outer_height = 0;
  33. var tl_outer_width = 0;
  34. var tl_width = 0;
  35. var tl_height = 0;
  36. var I = null;
  37. var tl_tab_on = sitting.tab_on;
  38. var tl_find_on = tl_tab.index($(this).find("." + tl_tab_on));
  39. var tl_child_on = tl_index = -1 == tl_find_on ? tl_index : tl_find_on;//默认on
  40. var tl_new_index = tl_index;
  41. var tl_pages = tl_box_size >= 1 ? 0 != tl_box_size % 1 ? tl_box_size % 1 : 1 : 0;
  42. //alert(tl_pages)
  43. if (0 == tl_tab_sise && (tl_tab_sise = tl_box_size), "false" == sitting.page || 0 == sitting.page ? !1 : !0) {//如果分页
  44. if (tl_box_size >= 1) {
  45. if ("TL_Left" == tl_type || "TL_Top" == tl_type) {
  46. tl_tab_sise = 0 != tl_box_size % 1 ? (0 ^ tl_box_size / 1) + 1 : tl_box_size / 1
  47. }
  48. else {
  49. var V = tl_box_size - 1;
  50. tl_tab_sise = 1 + parseInt(0 != V % 1 ? V / 1 + 1 : V / 1), 0 >= tl_tab_sise && (tl_tab_sise = 1)
  51. }
  52. }
  53. else {
  54. tl_tab_sise = 1;
  55. }
  56. tl_tab.html("");
  57. var tl_item_num = "";
  58. if (1 == sitting.page || "true" == sitting.page) {
  59. for (var q1 = 0; tl_tab_sise > q1; q1++) tl_item_num += "<li><a href='javascript:void(0);'>" + (q1 + 1) + "<a/></li>"
  60. }
  61. else {
  62. for (var q2 = 0; tl_tab_sise > q2; q2++) tl_item_num += sitting.page.replace("$", q2 + 1)
  63. }
  64. //alert(tl_item_num)
  65. tl_tab.html(tl_item_num);
  66. var tl_tab = tl_tab.children();
  67. }
  68. if (tl_box_size >= 1) {
  69. tl_box.children().each(function() {
  70. $(this).width() > tl_width && (
  71. tl_width = $(this).width(),
  72. tl_outer_width = $(this).outerWidth(!0)
  73. ),
  74. $(this).height() > tl_height && (
  75. tl_height = $(this).height(),
  76. tl_outer_height = $(this).outerHeight(!0)
  77. )
  78. });
  79. function tl_list_each() {
  80. for (var a1 = 0; 1 > a1; a1++)
  81. tl_box.children().eq(a1).clone().addClass("clone").appendTo(tl_box);
  82. for (var a2 = 0; tl_pages > a2; a2++)
  83. tl_box.children().eq(tl_box_size - a2 - 1).clone().addClass("clone").prependTo(tl_box)
  84. };
  85. switch (tl_type) {
  86. case "TL_Display":
  87. tl_box.css({
  88. position: "relative",
  89. width: tl_outer_width,
  90. height: tl_outer_height
  91. }).children().css({
  92. width: tl_width,
  93. position: "absolute",
  94. left: 0,
  95. top: 0,
  96. display: "none"
  97. });
  98. break;
  99. case "TL_Top":
  100. tl_list_each(),
  101. tl_box.wrap('<div class="df_slide_box" style="overflow:hidden; position:relative; height:' + tl_outer_height + 'px"></div>').css({
  102. top: -(tl_index * 1) * tl_outer_height,
  103. position: "relative",
  104. padding: 0,
  105. margin: 0
  106. }).children().css({
  107. height: tl_height
  108. });
  109. break;
  110. case "TL_Left":
  111. tl_list_each(),
  112. tl_box.wrap('<div class="df_slide_box" style="overflow:hidden; position:relative; width:' * tl_outer_width + 'px"></div>').css({
  113. width: (tl_box_size + 1 + tl_pages) * tl_outer_width,
  114. position: "relative",
  115. overflow: "hidden",
  116. padding: 0,
  117. margin: 0,
  118. left: -(tl_pages + tl_index * 1) * tl_outer_width
  119. }).children().css({
  120. width: tl_width,
  121. float: "left"
  122. });
  123. break;
  124. }
  125. }
  126. var tl_elm = function(elm) {
  127. var tl_str = elm * 1;
  128. return elm == tl_tab_sise ? tl_str = tl_box_size : -1 == elm && 0 != tl_box_size % 1 && (tl_str = -tl_box_size % 1),
  129. tl_str
  130. };
  131. var tl_init = function(k) {
  132. if (tl_child_on != tl_index || k) {
  133. if ((tl_new_index = tl_index, tl_index >= tl_tab_sise ? tl_index = 0 : 0 > tl_index && (tl_index = tl_tab_sise - 1)),
  134. ($.isFunction(sitting.fun_start) && sitting.fun_start(
  135. tl_index,
  136. tl_tab_sise,
  137. $(this),
  138. $(sitting.tab, $(this)),
  139. tl_box,
  140. tl_prev,
  141. tl_next
  142. )
  143. ) , tl_box_size >= 1){
  144. switch (tl_type) {
  145. case "TL_Fade":
  146. tl_box.children().stop(false, false).eq(tl_index).animate({
  147. opacity: "show"
  148. }, tl_timer, "swing", function() {
  149. $.isFunction(sitting.fun_end) && (
  150. sitting.fun_end(
  151. tl_index,
  152. tl_tab_sise,
  153. $(this),
  154. $(sitting.tab, $(this)),
  155. tl_box,
  156. tl_prev,
  157. tl_next
  158. )
  159. )
  160. }).siblings().hide();
  161. break;
  162. case "TL_Display":
  163. tl_box.children().stop(false, false).eq(tl_index).animate({
  164. opacity: "show"
  165. }, tl_timer, "swing", function() {
  166. $.isFunction(sitting.fun_end) && (
  167. sitting.fun_end(
  168. tl_index,
  169. tl_tab_sise,
  170. $(this),
  171. $(sitting.tab, $(this)),
  172. tl_box,
  173. tl_prev,
  174. tl_next
  175. )
  176. )
  177. }).siblings().animate({
  178. opacity: "hide"
  179. }, tl_timer, "swing");
  180. break;
  181. case "TL_Left":
  182. tl_box.stop(false, true).animate({
  183. left: -(tl_elm(tl_new_index) + tl_pages) * tl_outer_width
  184. }, tl_timer, "swing", function() {
  185. -1 >= tl_new_index ?
  186. tl_box.css({
  187. left: -(tl_pages + (tl_tab_sise - 1) * 1) * tl_outer_width
  188. })
  189. :
  190. tl_new_index >= tl_tab_sise && tl_box.css({
  191. left: -tl_pages * tl_outer_width
  192. }),
  193. $.isFunction(sitting.fun_end) && (
  194. sitting.fun_end(
  195. tl_index,
  196. tl_tab_sise,
  197. $(this),
  198. $(sitting.tab, $(this)),
  199. tl_box,
  200. tl_prev,
  201. tl_next
  202. )
  203. )
  204. });
  205. break;
  206. case "TL_Top":
  207. tl_box.stop(false, false).animate({
  208. top: -(tl_elm(tl_new_index) + tl_pages) * tl_outer_height
  209. }, tl_timer, "swing", function() {
  210. -1 >= tl_new_index ?
  211. tl_box.css({
  212. top: -(tl_pages + (tl_tab_sise - 1) * 1) * tl_outer_height
  213. })
  214. :
  215. tl_new_index >= tl_tab_sise && tl_box.css({
  216. top: -tl_pages * tl_outer_height
  217. }),
  218. $.isFunction(sitting.fun_end) && (
  219. sitting.fun_end(
  220. tl_index,
  221. tl_tab_sise,
  222. $(this),
  223. $(sitting.tab, $(this)),
  224. tl_box,
  225. tl_prev,
  226. tl_next
  227. )
  228. )
  229. });
  230. break;
  231. }
  232. tl_tab.removeClass(tl_tab_on).eq(tl_index).addClass(tl_tab_on),
  233. tl_child_on = tl_index,
  234. "true" || (
  235. tl_next.removeClass("df_stop_next"),
  236. tl_prev.removeClass("df_stop_prev"),
  237. 0 == tl_index && tl_prev.addClass("df_stop_prev"),
  238. tl_index == tl_tab_sise - 1 && tl_next.addClass("df_stop_next")
  239. ),
  240. tl_page_box.html("<strong>" + (tl_index + 1) + "</strong><b> / " + tl_tab_sise + "</b>")
  241. }
  242. }
  243. };
  244. tl_init(!0);
  245. var tl_clear = null;
  246. if ("tl_hover"===sitting.actions){
  247. tl_tab.hover(function() {
  248. var a7 = tl_tab.index(this);
  249. I = setTimeout(function() {
  250. tl_index = a7,
  251. tl_init(),
  252. clearInterval(tl_clear),
  253. tl_clear = setInterval(function() {
  254. tl_index++, tl_init()
  255. }, tl_get_speed)
  256. }, 100)
  257. }, function() {
  258. clearTimeout(I)
  259. })
  260. }
  261. if ("tl_click"===sitting.actions){
  262. tl_tab.click(function() {
  263. tl_index = tl_tab.index(this),
  264. tl_init(),
  265. clearInterval(tl_clear),
  266. tl_clear = setInterval(function() {
  267. tl_index++, tl_init()
  268. }, tl_get_speed)
  269. })
  270. }
  271. tl_next.click(function() {
  272. ("true" || tl_index != tl_tab_sise - 1) && (
  273. tl_index++,
  274. tl_init(),
  275. clearInterval(tl_clear),
  276. tl_clear = setInterval(function() {
  277. tl_index++, tl_init()
  278. }, tl_get_speed)
  279. )
  280. });//右按扭
  281. tl_prev.click(function() {
  282. ("true" || 0 != tl_index) && (
  283. tl_index--,
  284. tl_init(),
  285. clearInterval(tl_clear),
  286. tl_clear = setInterval(function() {
  287. tl_index++, tl_init()
  288. }, tl_get_speed)
  289. )
  290. });//左按扭
  291. if (sitting.auto_play){
  292. tl_clear = setInterval(function() {
  293. tl_index++, tl_init()
  294. }, tl_get_speed)
  295. $(this).hover(function(){
  296. clearInterval(tl_clear)
  297. },function(){
  298. clearInterval(tl_clear),
  299. tl_clear = setInterval(function() {
  300. tl_index++, tl_init()
  301. }, tl_get_speed)
  302. });
  303. }
  304. })
  305. }
  306. })(jQuery);