Imagelist.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*H5 拖拽上传图片 李泉*/
  2. Namespace.register("U.Control.ImL"); //注册命名空间
  3. U.Control.ImL.scroe= 0;
  4. U.Control.ImL.screen = 0;
  5. U.Control.ImL.buer;
  6. U.Control.ImL.time;
  7. U.Control.ImL.time2;
  8. U.Control.ImL.loadbest = function () { /*初始化函数 返回最大的div 并且给元素附事件*/
  9. var g = $$("div", {}, document.body);
  10. var best = $$("div", { "id": "bests" }, g);
  11. var banner = $$("div", { "id": "banner" }, best);
  12. var box = $$("ul", { "id": "box", "width": "300%", "position": "relative", "left": "0%" }, banner);
  13. var li1 = $$("li", { "id": "img0" }, box);
  14. var file1 = $$("input", { "id": "file1", "type": "file" }, li1);
  15. var li2 = $$("li", { "id": "img1" }, box);
  16. var file2 = $$("input", { "id": "file2", "type": "file" }, li2);
  17. var li3 = $$("li", { "id": "img2" }, box);
  18. var file2 = $$("input", { "id": "file3", "type": "file" }, li3);
  19. var leftbox = $$("div", { "id": "leftbox" }, banner);
  20. var left = $$("div", { "id": "left" }, leftbox);
  21. var right = $$("div", { "id": "right" }, leftbox);
  22. var page = $$("ol", { "id": "page" }, banner);
  23. var pageli1 = $$("li", { "id": "0" }, page);
  24. var pageli2 = $$("li", { "id": "1" }, page);
  25. var pageli3 = $$("li", { "id": "2" }, page);
  26. U.Control.ImL.dei();
  27. return best;
  28. }
  29. /*window.onload = function () {
  30. U.Control.ImL.loadbest();
  31. } */
  32. U.Control.ImL.dei = function () {
  33. var box = $("#box li");
  34. for (var i = 0; i < box.length; i++) { //ol 对应 图片
  35. box[i].id = "img" + i;
  36. box[i].style.opacity = 1;
  37. box[i].style.zIndex = 2;
  38. box[i].childNodes[0].addEventListener("change", function () {
  39. var reader = new FileReader();
  40. reader.readAsDataURL(this.files[0]);
  41. var g = this.parentNode.id.replace(/[^0-9]+/g, '');
  42. reader.onload = function (e) {
  43. // $("#test")[0].src = e.target.result;
  44. $("#box li")[g].style.backgroundImage = 'url(' + e.target.result + ')';
  45. }
  46. });
  47. }
  48. U.Control.ImL.time = setTimeout("U.Control.ImL.start()", 3000); //开始计时
  49. U.Control.ImL.scroe = 0;
  50. U.Control.ImL.restart();
  51. $("#box")[0].style.left = -0 * 100 + "%";
  52. $("#page li")[0].style.cssText = "background-color:skyblue;";
  53. var a = $("#page li");
  54. for (var i = 0; i < a.length; i++) {
  55. a[i].onclick = function () {
  56. U.Control.ImL.empty();
  57. var img = $("#box")[0];
  58. var imgLeft = parseInt(img.style.left);
  59. U.Control.ImL.scroe = parseInt(this.id);
  60. if (this.id == 0) {
  61. U.Control.ImL.cl();
  62. U.Control.ImL.restart();
  63. img.style.left = -0 * 100 + "%";
  64. $("#page li")[0].style.cssText = "background-color:skyblue;";
  65. }
  66. if (this.id == 1) {
  67. U.Control.ImL.cl();
  68. U.Control.ImL.restart();
  69. img.style.left = -1 * 100 + "%";
  70. $("#page li")[1].style.cssText = "background-color:skyblue;";
  71. }
  72. if (this.id == 2) {
  73. U.Control.ImL.cl();
  74. U.Control.ImL.restart();
  75. img.style.left = -2 * 100 + "%";
  76. $("#page li")[2].style.cssText = "background-color:skyblue;";
  77. }
  78. }
  79. }
  80. $("#right")[0].onclick = function () { //向右切换图片
  81. if (U.Control.ImL.buer == true) return;
  82. U.Control.ImL.restart();
  83. U.Control.ImL.empty();
  84. var img = $("#box")[0];
  85. if (U.Control.ImL.scroe == 0) {
  86. $("#page li")[1].style.cssText = "background-color:skyblue;";
  87. U.Control.ImL.intoright((-0 - 1) * 100);
  88. U.Control.ImL.scroe += 1;
  89. return;
  90. }
  91. if (U.Control.ImL.scroe == 1) {
  92. $("#page li")[2].style.cssText = "background-color:skyblue;";
  93. U.Control.ImL.intoright((-1 - 1) * 100);
  94. U.Control.ImL.scroe += 1;
  95. return;
  96. }
  97. if (U.Control.ImL.scroe == 2) {
  98. img.style.left = 0 + "%";
  99. $("#page li")[0].style.cssText = "background-color:skyblue;";
  100. U.Control.ImL.scroe += 1;
  101. return;
  102. }
  103. if (U.Control.ImL.scroe >= 3) {
  104. U.Control.ImL.scroe = 0;
  105. $("#page li")[1].style.cssText = "background-color:skyblue;";
  106. U.Control.ImL.intoright((-0 - 1) * 100);
  107. U.Control.ImL.scroe += 1;
  108. }
  109. }
  110. $("#left")[0].onclick = function () {//向左切换图片
  111. if (U.Control.ImL.buer == true) return;
  112. U.Control.ImL.restart();
  113. U.Control.ImL.empty();
  114. var img = $("#box")[0];
  115. if (U.Control.ImL.scroe == 0) {
  116. img.style.left = -200 + "%";
  117. $("#page li")[2].style.cssText = "background-color:skyblue;";
  118. U.Control.ImL.scroe = 2;
  119. return;
  120. }
  121. if (U.Control.ImL.scroe == 1) {
  122. $("#page li")[0].style.cssText = "background-color:skyblue;";
  123. U.Control.ImL.intoleft(0 * 100);
  124. U.Control.ImL.scroe -= 1;
  125. return;
  126. }
  127. if (U.Control.ImL.scroe == 2) {
  128. $("#page li")[1].style.cssText = "background-color:skyblue;";
  129. U.Control.ImL.intoleft(-1 * 100);
  130. U.Control.ImL.scroe -= 1;
  131. return;
  132. }
  133. }
  134. }
  135. U.Control.ImL.restart = function () { //重新计时
  136. clearTimeout(U.Control.ImL.time);
  137. U.Control.ImL.time = setTimeout("U.Control.ImL.start()", 3000);
  138. }
  139. U.Control.ImL.cl = function () { //判断是否正在移动
  140. if (U.Control.ImL.buer = true) {
  141. var a = $("#box li");
  142. for (var i = 0; i < a.length; i++) {
  143. a[i].style.opacity = 1;
  144. }
  145. clearTimeout(U.Control.ImL.time2);
  146. U.Control.ImL.buer = false;
  147. }
  148. }
  149. U.Control.ImL.intoright = function (w) { // 右移动画
  150. U.Control.ImL.buer = true;
  151. var dei;
  152. var pl = $("#page li");
  153. for(var i = 0;i<pl.length;i++){
  154. if(pl[i].style.backgroundColor=='skyblue'){
  155. dei = pl[i].id-1;
  156. }
  157. }
  158. var pageL = $("#page li");
  159. var img = $("#box")[0];
  160. if (w != undefined) {
  161. U.Control.ImL.screen = w;
  162. }
  163. var imgLeft = parseInt(img.style.left);
  164. if (imgLeft == U.Control.ImL.screen) {
  165. U.Control.ImL.screen = 0;
  166. U.Control.ImL.buer = false;
  167. $("#box li")[dei].style.opacity=1;
  168. return;
  169. }
  170. img.style.left = imgLeft - 1 + "%";
  171. $("#box li")[dei].style.opacity-=0.015;
  172. $("#box li")[dei].style.zIndex=0;
  173. U.Control.ImL.time2 = setTimeout("U.Control.ImL.intoright()", 20);
  174. }
  175. U.Control.ImL.intoleft = function (w) { //坐移动画
  176. U.Control.ImL.buer = true;
  177. var dei;
  178. var pl = $("#page li");
  179. for(var i = 0;i<pl.length;i++){
  180. if(pl[i].style.backgroundColor=='skyblue'){
  181. dei = parseInt(pl[i].id)+1;
  182. }
  183. }
  184. var img = $("#box")[0];
  185. if (w != undefined) {
  186. U.Control.ImL.screen = w;
  187. }
  188. var imgLeft = parseInt(img.style.left);
  189. if (imgLeft == U.Control.ImL.screen) {
  190. U.Control.ImL.screen = 0;
  191. U.Control.ImL.buer = false;
  192. $("#box li")[dei].style.opacity=1;
  193. return;
  194. }
  195. img.style.left = imgLeft + 1 + "%";
  196. $("#box li")[dei].style.opacity-=0.015;
  197. U.Control.ImL.time2=setTimeout("U.Control.ImL.intoleft()", 20);
  198. }
  199. U.Control.ImL.start = function () { //开始计时
  200. document.getElementById("file1").value;
  201. U.Control.ImL.buer = true;
  202. var img = $("#box")[0];
  203. // img.style.Left="-32+"%";"
  204. if (U.Control.ImL.scroe != 2) {
  205. U.Control.ImL.empty();
  206. if (U.Control.ImL.scroe == 0) {
  207. $("#page li")[1].style.cssText = "background-color:skyblue;";
  208. }
  209. if (U.Control.ImL.scroe == 1) {
  210. $("#page li")[2].style.cssText = "background-color:skyblue;";
  211. }
  212. if (U.Control.ImL.scroe == 2) {
  213. $("#page li")[0].style.cssText = "background-color:skyblue;";
  214. }
  215. U.Control.ImL.scroe += 1;
  216. var imgLeft = parseInt(img.style.left);
  217. U.Control.ImL.intoright(imgLeft - 100);
  218. }
  219. /* if (U.Control.ImL.scroe >= 3) {
  220. U.Control.ImL.scroe = 0;
  221. img.style.left = 0 + "%";
  222. return;
  223. }*/
  224. else {
  225. U.Control.ImL.scroe = 0;
  226. U.Control.ImL.empty();
  227. img.style.left = 0 + "%";
  228. $("#page li")[0].style.cssText = "background-color:skyblue;";
  229. }
  230. U.Control.ImL.time = setTimeout("U.Control.ImL.start()", 3000);
  231. }
  232. U.Control.ImL.empty = function () { //清空 ol background-color
  233. var a = $("#page li");
  234. for (var i = 0; i < a.length; i++) {
  235. a[i].style.cssText = "background-color:white;";
  236. }
  237. }