template.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. $(function () {
  2. var windowWidth = $(window).width();
  3. function setRem () {
  4. var windowWidth = $(window).width();
  5. if (windowWidth <= 750) {
  6. var fs = windowWidth/750 * 6.25 * 100;
  7. $('html').css('font-size', fs + '%'); // 1rem = 100px;
  8. }
  9. };
  10. setRem();
  11. $(window).resize(setRem);
  12. // 举报 单选
  13. $("#reportModal .report ul li").click(function () {
  14. $("#reportModal .report ul li").find(".icon").removeClass("icon-radio-checked").siblings("input[type=radio]").prop("checked", false);
  15. $(this).find(".icon").addClass("icon-radio-checked").siblings("input[type=radio]").prop("checked", true);
  16. // console.log($("#reportModal :checked").val());
  17. });
  18. // 举报保存
  19. $("#reportModal .report .save").click(function () {
  20. var checkedRadio = $("#reportModal .report ul");
  21. var textarea = $("#reportModal .report textarea");
  22. var email = $("#reportModal .report input[name=email]");
  23. var emailValidation = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
  24. if (checkedRadio.find(":checked").length > 0) {
  25. checkedRadio.parents(".form-group").removeClass("form-error");
  26. } else {
  27. checkedRadio.parents(".form-group").addClass("form-error");
  28. }
  29. if (textarea.val().length > 0) {
  30. textarea.parents(".form-group").removeClass("form-error");
  31. } else {
  32. textarea.parents(".form-group").addClass("form-error");
  33. }
  34. if (emailValidation.test(email.val())) {
  35. email.parents(".form-group").removeClass("form-error");
  36. } else {
  37. email.parents(".form-group").addClass("form-error");
  38. }
  39. var errorLength = $("#reportModal .report .form-error").length;
  40. if (errorLength > 0) {
  41. $("#reportModal").modal("show");
  42. $("#reportSuccess").modal("hide");
  43. } else {
  44. $("#reportModal").modal("hide");
  45. $("#reportSuccess").modal("show");
  46. }
  47. });
  48. $("body").css("padding-top", 0);
  49. });
  50. function screenWidthFun() {
  51. // 截图宽度
  52. var screenWidth = 0;
  53. $(".template-common .app-screen ul li").each(function () {
  54. var $img = $(this).find("img");
  55. var ml = parseInt($(this).css("margin-right"));
  56. var imgWidth = 0;
  57. if ($img.get(0).complete) {
  58. // $img.css("width", $img.width());
  59. // imgWidth = parseInt($img.css("width")) + 20;
  60. imgWidth = $img.width() + ml;
  61. screenWidth += imgWidth;
  62. $(".template-common .app-screen ul").width(screenWidth + 5);
  63. // console.log("图片已加载");
  64. // console.log("imgWidth: " + imgWidth);
  65. // console.log("screenWidth " + screenWidth);
  66. } else {
  67. $img.load(function () {
  68. // $(this).css("width", this.width);
  69. // imgWidth = parseInt($img.css("width")) + 20;
  70. imgWidth = $(this).width() + ml;
  71. screenWidth += imgWidth;
  72. $(".template-common .app-screen ul").width(screenWidth + 5);
  73. // console.log("图片未加载");
  74. // console.log("imgWidth: " + imgWidth);
  75. // console.log("screenWidth " + screenWidth);
  76. });
  77. }
  78. });
  79. };
  80. screenWidthFun();
  81. // 弹窗
  82. var Modal = function() { // Modal为匿名函数执行完的返回值
  83. function templateModal(obj) {
  84. $("#templateModal").remove();
  85. var templateModalHtml = '<div class="modal fade ms-modal" id="templateModal" tabindex="-1" role="dialog">\n' +
  86. ' <div class="modal-dialog modal-sm" role="document">\n' +
  87. ' <div class="modal-content">\n' +
  88. ' <div class="modal-body">\n' +
  89. ' <div class="template-modal">\n' +
  90. ' <div class="m-top">\n' +
  91. ' <div class="title1"></div>\n' +
  92. ' <div class="title2"></div>\n' +
  93. ' </div>\n' +
  94. ' <div class="modal-p"></div>\n' +
  95. ' <button type="button" class="ms-btn ms-btn-primary modal-btn" data-dismiss="modal"></button>\n' +
  96. ' </div>\n' +
  97. ' </div>\n' +
  98. ' </div>\n' +
  99. ' </div>\n' +
  100. '</div>\n';
  101. $("body").append(templateModalHtml);
  102. $("#templateModal").find(".m-top").css("background-image", "url(./static/index/image/" + obj.imgName +")");
  103. $("#templateModal").find(".title1").text(obj.title1);
  104. $("#templateModal").find(".title2").html(obj.title2);
  105. $("#templateModal").find(".modal-p").html(obj.p).css("text-align", obj.align);
  106. $("#templateModal").find(".modal-btn").text(obj.btnText).addClass(obj.btnClass);
  107. $("#templateModal").modal('show');
  108. }
  109. function generalModal(obj) { // 通用弹窗
  110. $("#generalModal").remove();
  111. var generalModalHtml = '<div class="modal fade ms-modal" id="generalModal" tabindex="-1" role="dialog">\
  112. <div class="modal-dialog modal-sm" role="document">\
  113. <div class="modal-content">\
  114. <div class="modal-body">\
  115. <div class="text-center">\
  116. <div class="modal-icon"><span class="icon icon-class mb5"></span></div>\
  117. <div class="color-333 bold font16 title"></div>\
  118. <div class="color-333 modal-p"></div>\
  119. <div>\
  120. <a href="javascript:;" class="ms-btn cancel-btn"></a>\
  121. <button type="button" class="ms-btn ms-btn-primary success-btn"></button>\
  122. </div>\
  123. </div>\
  124. </div>\
  125. </div>\
  126. </div>\
  127. </div>';
  128. $("body").append(generalModalHtml);
  129. $("#generalModal").find(".icon-class").addClass(obj.iconClass);
  130. $("#generalModal").find(".title").text(obj.title);
  131. $("#generalModal").find(".modal-p").html(obj.p).css("text-align", obj.align);
  132. $("#generalModal").find(".success-btn").text(obj.successBtnText);
  133. $("#generalModal").find(".cancel-btn").text(obj.cancelBtnText);
  134. if (obj.backdrop) {
  135. $("#generalModal").modal({backdrop: 'static', keyboard: false});
  136. } else {
  137. $("#generalModal").modal("show");
  138. }
  139. $("#generalModal").find(".success-btn").click(obj.successCallback);
  140. $("#generalModal").find(".cancel-btn").click(obj.cancelCallback);
  141. var iconClassLength = $("#generalModal").find(".icon-class").attr("class").replace(/\s*/g,"").length;
  142. // console.log(iconClassLength);
  143. if (iconClassLength == 17) {
  144. $("#generalModal").find(".modal-icon").hide();
  145. } else {
  146. $("#generalModal").find(".modal-icon").show();
  147. }
  148. // 点击按钮是否关闭弹窗
  149. $("#generalModal").find(".success-btn").click(function () {
  150. if (obj.successBtnModal) {
  151. $("#generalModal").modal("hide");
  152. }
  153. });
  154. $("#generalModal").find(".cancel-btn").click(function () {
  155. if (obj.cancelBtnModal) {
  156. $("#generalModal").modal("hide");
  157. }
  158. });
  159. };
  160. return {
  161. templateModal: templateModal, // 带确定按钮 弹窗
  162. generalModal: generalModal // 带确定按钮 弹窗
  163. }
  164. }();
  165. /*
  166. Modal.templateModal({
  167. imgName: "modal-bg-2.jpg",
  168. title1: '提示1',
  169. title2: '该账户尚未实名,每天只能下载5次',
  170. p: '建议您:<br>尽快登录第八区网站,点击右上角未实名认证,进行认证。<br>认证通过每天将免费获得1000次下载。',
  171. align: 'left', // 居左 left, 居中 center, 居右 right
  172. btnText: '知道了',
  173. btnClass: "modal-btn1"
  174. });
  175. */