banner_phone.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //丘润成,叶延裕,傅昊
  2. Namespace.register("U.Control.bp"); //浏览列表命名空间
  3. U.Control.bp.U_BP_aaa = 1;
  4. U.Control.bp.U_BP_nowWidth;
  5. U.Control.bp.U_BP_nowHeight;
  6. //第一个函数
  7. U.Control.bp.Z = function () {
  8. var U_BP_kuan = $$("div", { "style": { "width": "100%", "height": "100%", "float": "left"} }, document.body);
  9. U.Control.bp.U_BP_y(U_BP_kuan);
  10. var U_BP_tpk = $("#U_BP_tpk")[0];
  11. U_BP_tpk.style.transform = "translateX(0px)";
  12. U.Control.bp.A();
  13. return U_BP_kuan;
  14. }
  15. //动态创建轮播图片
  16. U.Control.bp.U_BP_y = function (U_BP_kuan) {
  17. var U_BP_a = $$("div", { "style": { "width": "400px", "height": "300px", "overflow": " hidden", "position": " absolute" }, "id": "U_BP_ck" }, U_BP_kuan);
  18. var U_BP_b = $$("ul", { "style": { "float": "left", "height": "300px", "width": " 1200px", " position": " absolute", "left": "0", "top": "0", "list-style-type": " none" }, "id": "U_BP_tpk" }, U_BP_a);
  19. var U_BP_c = $$("li", { "style": { "float": "left", "height": "300px", "width": " 400px", "list-style-type": " none", "background": "url(http://d.1473.cn/controls/phone/banner_phone/img/a.jpeg)", "background-size": "100% 100%"} }, U_BP_b);
  20. var U_BP_d = $$("li", { "style": { "float": "left", "height": "300px", "width": " 400px", "list-style-type": " none", "background": "url(http://d.1473.cn/controls/phone/banner_phone/img/b.jpg)", "background-size": "100% 100%"} }, U_BP_b);
  21. var U_BP_e = $$("li", { "style": { "float": "left", "height": "300px", "width": " 400px", "list-style-type": " none", "background": "url(http://d.1473.cn/controls/phone/banner_phone/img/c.jpg)", "background-size": "100% 100%"} }, U_BP_b);
  22. var U_BP_f = $$("li", { "style": { "float": "left", "height": "300px", "width": " 400px", "list-style-type": " none", "background": "url(http://d.1473.cn/controls/phone/banner_phone/img/d.jpg)", "background-size": "100% 100%"} }, U_BP_b);
  23. var U_BP_g = $$("li", { "style": { "float": "left", "height": "300px", "width": " 400px", "list-style-type": " none", "background": "url(http://d.1473.cn/controls/phone/banner_phone/img/e.jpeg)", "background-size": "100% 100%"} }, U_BP_b);
  24. var U_BP_h = $$("div", { "style": { "width": "100%", "height": "76PX", "position": " absolute", " z-index": " 2", "bottom": " 0", "left": " 0", " padding": " 0", "border-top": " 1px solid #444", "background-image": "url(http://d.1473.cn/controls/phone/banner_phone/img/beijinggg.png)", "background-size": "100% 100%" }, "id": "U_BP_Stop" }, U_BP_kuan);
  25. var U_BP_i = $$("div", { "style": { "z-index": "999", "width": "100px", "height": "76px", "color": "#FFF", "font-size": "2.5em", "text-align": "center", "line-height": "76px" }, "innerHTML": "1/2", "id": "U_BP_Stop1" }, U_BP_h);
  26. var U_BP_j = $$("div", { "style": { "width": "30%", "height": "76px", "margin-top": "-68px", "margin-left": "67%" }, "id": "U_BP_Stop2" }, U_BP_h);
  27. var U_BP_k = $$("div", { "style": { "width": "50px", "height": "50px", "margin-left": "12px", "float": "left", "background-image": "url(http://d.1473.cn/controls/phone/banner_phone/img/preview1.png)", "background-size": "100% 100%" }, "id": "U_BP_Sbutton0", "onclick": "U.Control.bp.B()" }, U_BP_j);
  28. var U_BP_l = $$("div", { "style": { "width": "50px", "height": "50px", "margin-left": "12px", "float": "left", "background-image": "url(http://d.1473.cn/controls/phone/banner_phone/img/preview2.png)", "background-size": "100% 100%" }, "id": "U_BP_Sbutton1" }, U_BP_j);
  29. var U_BP_m = $$("div", { "style": { "width": "50px", "height": "50px", "margin-left": "12px", "float": "left", "background-image": "url(http://d.1473.cn/controls/phone/banner_phone/img/preview3.png)", "background-size": "100% 100%" }, "id": "U_BP_Sbutton2" }, U_BP_j);
  30. }
  31. U.Control.bp.A = function () {
  32. //定义touch需要用到的变量
  33. var U_BP_first_X,
  34. U_BP_first_Y,
  35. //记录初始的x坐标和y坐标
  36. U_BP_x,
  37. U_BP_y,
  38. U_BP_aboveX = 0;
  39. //记录上一次的X坐标
  40. var startXX;
  41. //获取当前的页面的宽度和高度
  42. U.Control.bp.U_BP_nowWidth = document.body.offsetWidth;
  43. U.Control.bp.U_BP_nowHeight = document.body.offsetHeight;
  44. var U_BP_tpk = $("#U_BP_tpk")[0];
  45. var U_BP_tpkt = $("#U_BP_tpk");
  46. var U_BP_ck = $("#U_BP_ck")[0];
  47. var U_BP_tpkc = U_BP_tpk.children.length;
  48. U_BP_ck.style.width = U.Control.bp.U_BP_nowWidth + "px";
  49. U_BP_ck.style.height = U.Control.bp.U_BP_nowHeight + "px";
  50. U_BP_tpk.style.width = U.Control.bp.U_BP_nowWidth * U_BP_tpkc + "px";
  51. U_BP_tpk.style.height = U.Control.bp.U_BP_nowHeight * U_BP_tpkc + "px";
  52. //获取translateX内容的正则表达式
  53. var execXX = /\.*translateX\((.*)px\)/i;
  54. //var execXX = \d{2};
  55. for (var i = 0; i < U_BP_tpk.children.length; i++) {
  56. U_BP_tpk.children[i].style.width = U.Control.bp.U_BP_nowWidth + "px";
  57. U_BP_tpk.children[i].style.height = U.Control.bp.U_BP_nowHeight + "px";
  58. }
  59. //手机touch事件
  60. U_BP_tpkt.bind("touchstart", function (e) {
  61. //手机开始滑动的触发的事件,记录初始坐标
  62. U_BP_tpk.style.transition = "";
  63. var touch = e.touches[0];
  64. U_BP_first_X = touch.pageX;
  65. }, false)
  66. U_BP_tpkt.bind("touchmove", function (e) {
  67. //滑动过程中改变图片的位置
  68. U.UF.EV.stopBubble();
  69. var touch = e.touches[0];
  70. U_BP_x = touch.pageX - U_BP_first_X;
  71. //U_BP_tpk.style.left = U_BP_aboveX + U_BP_x + "px";
  72. U_BP_tpk.style.transform = "translateX(" + (U_BP_aboveX + U_BP_x) + "px)";
  73. startXX = parseInt(execXX.exec(U_BP_tpk.style.transform)[1]);
  74. }, false)
  75. U_BP_tpkt.bind("touchend", function (e) {
  76. //循环判断当前banner的位置
  77. if (startXX > -U.Control.bp.U_BP_nowWidth / 2) {
  78. U_BP_tpk.style.cssText += "transition:0.5s all;"
  79. U_BP_tpk.style.transform = "translateX(0px)";
  80. startXX = parseInt(execXX.exec(U_BP_tpk.style.transform)[1]);
  81. }
  82. for (var i = 0; i < U_BP_tpkc - 2; i++) {
  83. if (startXX < -U.Control.bp.U_BP_nowWidth / 2 + i * -U.Control.bp.U_BP_nowWidth && startXX > (i + 1) * -U.Control.bp.U_BP_nowWidth + -U.Control.bp.U_BP_nowWidth / 2) {
  84. U_BP_tpk.style.cssText += "transition:0.5s all;"
  85. U_BP_tpk.style.transform = "translateX(" + ((i + 1) * -U.Control.bp.U_BP_nowWidth) + "px)";
  86. startXX = parseInt(execXX.exec(U_BP_tpk.style.transform)[1]);
  87. }
  88. }
  89. if (startXX < -U.Control.bp.U_BP_nowWidth * (U_BP_tpkc - 1) + U.Control.bp.U_BP_nowWidth / 2) {
  90. U_BP_tpk.style.cssText += "transition:0.5s all;"
  91. U_BP_tpk.style.transform = "translateX(" + (-U.Control.bp.U_BP_nowWidth * (U_BP_tpkc - 1)) + "px)";
  92. startXX = parseInt(execXX.exec(U_BP_tpk.style.transform)[1]);
  93. }
  94. U_BP_aboveX = parseInt(startXX);
  95. }, false);
  96. }
  97. //自动轮播函数
  98. U.Control.bp.B = function () {
  99. //判断定时器是否存在,如果存在则清除定时器
  100. if (U.Control.bp.U_BP_aaa == 2) {
  101. U.Control.bp.U_BP_aaa = 1;
  102. clearInterval(timer);
  103. return;
  104. }
  105. //如果定时器不存在 使图片轮播
  106. if (U.Control.bp.U_BP_aaa == 1) {
  107. U.Control.bp.U_BP_aaa = 2;
  108. var U_BP_tpk = $("#U_BP_tpk")[0];
  109. var U_BP_U_BP_nowWidth = document.body.offsetWidth;
  110. //获取translateX参数的正则表达式
  111. var U_BP_execXX = /\.*translateX\((.*)px\)/i;
  112. var U_BP_startXX;
  113. U_BP_startXX = parseInt(U_BP_execXX.exec(U_BP_tpk.style.transform)[1]);
  114. //获取当前的translateX
  115. var U_BP_oli = U_BP_tpk.getElementsByTagName('li');
  116. U_BP_tpk.style.width = U_BP_oli[0].offsetWidth * U_BP_oli.length + 'px';
  117. U_BP_tpk.style.transition = "0.5s all";
  118. window.timer = setInterval(function () {
  119. //用setInterval使图片不断轮播
  120. U_BP_tpk.style.transform = "translateX(" + (U_BP_startXX - U_BP_U_BP_nowWidth) + "px)";
  121. U_BP_startXX = parseInt(U_BP_execXX.exec(U_BP_tpk.style.transform)[1]);
  122. if (U_BP_startXX <= U.Control.bp.U_BP_nowWidth * -U_BP_tpk.children.length) {
  123. U_BP_tpk.style.transform = "translateX(0px)";
  124. U_BP_startXX = parseInt(U_BP_execXX.exec(U_BP_tpk.style.transform)[1]);
  125. //获取当前的translateX
  126. }
  127. }, 1500)
  128. return;
  129. }
  130. }