ScrImg.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //14互联网G5-2 杨思强 刘希鹏 钟兆立
  2. Namespace.register("U.Control.SI"); //命名空间
  3. /*window.onload = function () {
  4. U.Control.SI.GetWinSize();
  5. U.Control.SI.window();
  6. };*/
  7. //调用U.Control.SI.window();生成初始图片 初始函数
  8. //test
  9. //监听窗口大小变化 图片查看器大小也随着改变
  10. //window.onresize = function () {
  11. // U.Control.SI.Change();
  12. //}
  13. //创建图片查看器 主要功能函数 返回 点击后的图片和功能按钮
  14. U.Control.SI = function (Array, i) { //Array 传入图片地址 i 第几张图片
  15. if (!$("#U_SI_B")[0]) {
  16. var U_C_SI_M = $$("div", { "id": "U_SI_C", "style": { "display": "block"} }, $("body")[0]); //主体
  17. var U_C_SI_B = $$("div", { "id": "U_SI_B", "className": "U_SI_B", "onclick": [[U.Control.SI]], "style": { "display": "block"} }, U_C_SI_M); //背景
  18. // U_C_SI_B.onclick = function () { U.Control.SI(Array, i); };
  19. var U_C_SI = $$("div", { "id": "U_SI", "className": "U_SI" }, U_C_SI_M); //内容区域
  20. var U_C_SI_Box = $$("div", { "id": "U_SI_Box", "class": "U_SI_Box" }, U_C_SI); //图片div
  21. var U_C_SI_Img = $$("img", { "id": "U_SI_Img", "class": "U_SI_Img" }, U_C_SI_Box); //图片标签
  22. $('#U_SI_Img')[0].style.width = "100%";
  23. $('#U_SI_Img')[0].style.height = "100%"; //高宽
  24. var U_SI_But = $$("div", { "id": "U_SI_But", "class": "U_SI_But" }, U_C_SI); //按钮
  25. var U_SI_But_UL = $$("ul", { "style": { "padding-top": "5px"} }, U_SI_But);
  26. //var arr = ['xz', 'qp', 'xz', 'bc', 'left', 'bf', 'right'];
  27. var FunId = ["Amp", "Nar", "Rot", "Save", "Prev", "Play", "Next"]; //存储功能按钮图片
  28. for (var j = 0; j < FunId.length; j++) {
  29. if (FunId[j] == "Save") {
  30. var li = $$("li", { "id": "U_SI_But_" + FunId[j] }, U_SI_But_UL);
  31. var a = $$("a", { "id": "U_SI_B_Save" }, li);
  32. var img = $$("img", { "class": "U_SI_But_FI", "src": 'http://d.1473.cn/controls/pc/SrcImg/img/' + FunId[j] + '.png' }, a);
  33. var li = $$("li", { "style": { "width": "1.6px", "background-color": "rgba(255, 255, 255, 0.4)", "height": "25px", "margin": "1px 0px 0 10px", "padding": "0"} }, U_SI_But_UL);
  34. } else {
  35. var li = $$("li", { "id": "U_SI_But_" + FunId[j], "onclick": "U.Control.SI." + FunId[j] + "();" }, U_SI_But_UL);
  36. var img = $$("img", { "class": "U_SI_But_FI", "src": 'http://d.1473.cn/controls/pc/SrcImg/img/' + FunId[j] + '.png' }, li);
  37. }
  38. }
  39. U.Control.SI.Change();
  40. } else if ($("#U_SI_C")[0].style.display == "block") {
  41. U.Control.SI.Play(1);
  42. $("#U_SI_C")[0].style.display = "none";
  43. return;
  44. }
  45. var U_SI_Timer = null;
  46. $("#U_SI_B_Save")[0].href = $("#U_SI_B_Save")[0].download = $("#U_SI_Img")[0].src = Array[i].Url;
  47. U.Control.SI.UDE = Array;
  48. U.Control.SI.i = i;
  49. U.Control.SI.P = 0;
  50. U.Control.SI.Rora = 0;
  51. $("#U_SI_Img")[0].style.transform = 'rotate(' + 0 + 'deg)';
  52. $("#U_SI_C")[0].style.display = "block";
  53. return U_C_SI_M;
  54. }
  55. //创建三张图片实例 返回三张图片
  56. U.Control.SI.window = function () {
  57. var Array = [
  58. { "Url": "http://fs.1473.cn/ea65b74f-f181-4c74-a226-1c0a94903f9d.jpg", "Name": "1.jpg" },
  59. { "Url": "http://fs.1473.cn/67655a34-5285-4fcb-a1c2-a529a72e4685.jpg", "Name": "2.jpg" },
  60. { "Url": "http://fs.1473.cn/bbc4491f-12bc-4457-abfc-9f4a931fb4c1.jpg", "Name": "3.jpg" }
  61. ];
  62. return U.Control.SI.CreImg(Array);
  63. }
  64. //创建图片
  65. U.Control.SI.CreImg = function (Array) { //传入图片地址
  66. var i = 0;
  67. var U_SI = $$("div", { "style": { "width": "100$", "height": "100%"} }, $("Body")[0]);
  68. var U_SI_Wrap = $$("div", { "class": "U_SI_Wrap" }, U_SI);
  69. var U_SI_Wrap_ul = $$("ul", {}, U_SI_Wrap);
  70. //for (i = 0; a < Array.length; i++) {
  71. while (i < Array.length) { //循环输出 for也行的
  72. var li = $$("li", { "onclick": [[U.Control.SI, ([Array, i])]] }, U_SI_Wrap_ul);
  73. var img = $$("img", { "src": Array[i].Url }, li);
  74. i++;
  75. }
  76. var U_C_SI_M = $$("div", { "id": "U_SI_C", "style": { "display": "none"} }, U_SI); //主体
  77. var U_C_SI_B = $$("div", { "id": "U_SI_B", "className": "U_SI_B", "onclick": [[U.Control.SI]], "style": { "display": "block"} }, U_C_SI_M); //背景
  78. // U_C_SI_B.onclick = function () { U.Control.SI(Array, i); };
  79. var U_C_SI = $$("div", { "id": "U_SI", "className": "U_SI" }, U_C_SI_M); //内容区域
  80. var U_C_SI_Box = $$("div", { "id": "U_SI_Box", "class": "U_SI_Box" }, U_C_SI); //图片div
  81. var U_C_SI_Img = $$("img", { "id": "U_SI_Img", "class": "U_SI_Img" }, U_C_SI_Box); //图片标签
  82. $('#U_SI_Img')[0].style.width = "100%";
  83. $('#U_SI_Img')[0].style.height = "100%"; //高宽
  84. var U_SI_But = $$("div", { "id": "U_SI_But", "class": "U_SI_But" }, U_C_SI); //按钮
  85. var U_SI_But_UL = $$("ul", { "style": { "padding-top": "5px"} }, U_SI_But);
  86. //var arr = ['xz', 'qp', 'xz', 'bc', 'left', 'bf', 'right'];
  87. var FunId = ["Amp", "Nar", "Rot", "Save", "Prev", "Play", "Next"]; //存储功能按钮图片
  88. for (var j = 0; j < FunId.length; j++) {
  89. if (FunId[j] == "Save") {
  90. var li = $$("li", { "id": "U_SI_But_" + FunId[j] }, U_SI_But_UL);
  91. var a = $$("a", { "id": "U_SI_B_Save" }, li);
  92. var img = $$("img", { "class": "U_SI_But_FI", "src": 'http://d.1473.cn/controls/pc/SrcImg/img/' + FunId[j] + '.png' }, a);
  93. var li = $$("li", { "style": { "width": "1.6px", "background-color": "rgba(255, 255, 255, 0.4)", "height": "25px", "margin": "1px 0px 0 10px", "padding": "0"} }, U_SI_But_UL);
  94. } else {
  95. var li = $$("li", { "id": "U_SI_But_" + FunId[j], "onclick": "U.Control.SI." + FunId[j] + "();" }, U_SI_But_UL);
  96. var img = $$("img", { "class": "U_SI_But_FI", "src": 'http://d.1473.cn/controls/pc/SrcImg/img/' + FunId[j] + '.png' }, li);
  97. }
  98. }
  99. U.Control.SI.Change();
  100. U_C_SI_M.style.dispaly = "none";
  101. return U_SI;
  102. }
  103. //窗口大小改变图片查看器大小随之改变
  104. U.Control.SI.Change = function () {
  105. if ($("#U_SI_B")[0] && $("#U_SI_B")[0].style.display == "block") {
  106. U.Control.SI.GetWinSize(); //触发函数 去获取浏览器窗口的大小 创建出合适的div
  107. var U_C_SI_Hei = winHeight * 0.6 < 350 ? 350 : winHeight * 0.6;
  108. var U_C_SI_Wid = U_C_SI_Hei * 1.4;
  109. $("#U_SI").addAttrArray({
  110. "style": {
  111. "width": U_C_SI_Wid + "px",
  112. "height": U_C_SI_Hei + "px",
  113. "top": ((winHeight - U_C_SI_Hei - 20) < 0 ? 0 : (winHeight - U_C_SI_Hei - 20)) / 2 + "px",
  114. "left": ((winWidth - U_C_SI_Wid) < 0 ? 0 : (winWidth - U_C_SI_Wid)) / 2 + "px",
  115. "z-index": "9999"
  116. }
  117. });
  118. }
  119. }
  120. //获取窗口大小
  121. U.Control.SI.GetWinSize = function () {
  122. if (window.innerHeight && window.innerWidth) {
  123. winHeight = window.innerHeight;
  124. winWidth = window.innerWidth;
  125. }
  126. else if ((document.body) && (document.body.clientHeight) && (document.body.clientWidth)) {
  127. winHeight = document.body.clientHeight;
  128. winWidth = document.body.clientWidth;
  129. }
  130. // 通过深入Document内部对body进行检测,获取窗口大小
  131. if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
  132. winHeight = document.documentElement.clientHeight;
  133. winWidth = document.documentElement.clientWidth;
  134. }
  135. // return [winHeight, winWidth];
  136. }
  137. //缩小
  138. U.Control.SI.Amp = function () {
  139. var Amp_wid = parseInt($('#U_SI_Img')[0].style.width);
  140. var Amp_hei = parseInt($('#U_SI_Img')[0].style.height);
  141. if (Amp_wid == 50 || Amp_hei == 50) {
  142. return;
  143. }
  144. Amp_hei -= 10;
  145. Amp_wid -= 10;
  146. $("#U_SI_Img")[0].style.position = "relative";
  147. $("#U_SI_Img")[0].style.left = (100 - Amp_wid) / 2 + '%'; //就是每次缩小10%
  148. $("#U_SI_Img")[0].style.top = (100 - Amp_hei) / 2 + '%';
  149. $("#U_SI_Img")[0].style.width = Amp_wid + '%';
  150. $("#U_SI_Img")[0].style.height = Amp_hei + '%';
  151. U.Control.SI.Play(1);
  152. }
  153. //放大
  154. U.Control.SI.Nar = function () {
  155. var Amp_wid = parseInt($('#U_SI_Img')[0].style.width);
  156. var Amp_hei = parseInt($('#U_SI_Img')[0].style.height);
  157. if (Amp_wid == 100 || Amp_hei == 100) {
  158. alert("拖动功能暂时未做,只支持100%大小");
  159. return;
  160. }
  161. Amp_hei += 10;
  162. Amp_wid += 10;
  163. $("#U_SI_Img")[0].style.left = (100 - Amp_wid) / 2 + '%'; //每次放大10%
  164. $("#U_SI_Img")[0].style.top = (100 - Amp_hei) / 2 + '%';
  165. $("#U_SI_Img")[0].style.width = Amp_wid + '%';
  166. $("#U_SI_Img")[0].style.height = Amp_hei + '%';
  167. U.Control.SI.Play(1);
  168. }
  169. //旋转
  170. U.Control.SI.Rot = function () {
  171. U.Control.SI.Play(1);
  172. U.Control.SI.Rora++;
  173. // transform: rotate(90deg)scale(0.6,0.75);
  174. $("#U_SI_Img")[0].style.transform = 'rotate(' + U.Control.SI.Rora * 90 + 'deg)'; //每次旋转90度
  175. }
  176. //保存
  177. //U.Control.SI.Save = function () {
  178. //}
  179. //上一张
  180. U.Control.SI.Prev = function () {
  181. U.Control.SI.Play(1);
  182. if (U.Control.SI.i - 1 < 0) {//第一张限制
  183. U.Control.SI.i = U.Control.SI.UDE.length;
  184. }
  185. $("#U_SI_Img")[0].style.transform = 'rotate(' + 0 + 'deg)';
  186. U.Control.SI.i -= 1;
  187. $("#U_SI_B_Save")[0].href = $("#U_SI_B_Save")[0].download = $("#U_SI_Img")[0].src = U.Control.SI.UDE[U.Control.SI.i].Url;
  188. }
  189. //自动播放
  190. U.Control.SI.Play = function (T) {
  191. if (U.Control.SI.P == 1 || T == 1) {
  192. if (U.Control.SI.SrcSplit($("#U_SI_But_Play img")[0].src) == "Stp.png") {//如果按钮的src地址是停止按钮 停止计时器
  193. clearInterval(U_SI_Timer);
  194. }
  195. U.Control.SI.P = 0;
  196. $("#U_SI_But_Play img")[0].src = "http://d.1473.cn/controls/pc/SrcImg/img/Play.png"; //换成播放按钮
  197. } else {
  198. U.Control.SI.P = 1;
  199. $("#U_SI_Img")[0].style.transform = 'rotate(' + 0 + 'deg)'; //如果上一个操作有旋转 让播放的时候图片归回0deg
  200. $("#U_SI_But_Play img")[0].src = "http://d.1473.cn/controls/pc/SrcImg/img/Stp.png"; //换成暂停按钮
  201. U_SI_Timer = setInterval(function () {
  202. U.Control.SI.Next(0);
  203. }, 1000);
  204. }
  205. }
  206. //下一张
  207. U.Control.SI.Next = function (auto) {
  208. if (auto != 0) {
  209. U.Control.SI.Play(1);
  210. }
  211. $("#U_SI_Img")[0].style.transform = 'rotate(' + 0 + 'deg)';
  212. if (U.Control.SI.i + 1 == U.Control.SI.UDE.length) { //最后一张限制
  213. U.Control.SI.i = -1;
  214. }
  215. U.Control.SI.i += 1;
  216. $("#U_SI_B_Save")[0].href = $("#U_SI_B_Save")[0].download = $("#U_SI_Img")[0].src = U.Control.SI.UDE[U.Control.SI.i].Url;
  217. }
  218. //路径截取
  219. U.Control.SI.SrcSplit = function (Src) {
  220. // var Arr = new Array();
  221. Arr = Src.split("/");
  222. var result = Arr[Arr.length - 1];
  223. return result;
  224. }