header.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. $(document).ready(function () {
  2. // $("img").lazyload({
  3. // effect: "fadeIn"
  4. // });
  5. var phone = document.body.clientWidth <= 750 ? true : false;;
  6. var header = document.getElementsByClassName('header')[0];
  7. // pc端处理
  8. //顶部导航控制
  9. function headerTop(a, b) {
  10. console.log(a.length, '一级菜单')
  11. if (phone) return;
  12. for (var i = 0; i < a.length; i++) {
  13. var time = null;
  14. //控制鼠标悬浮时样式
  15. a[i].onmouseover = function (i) {
  16. return function () {
  17. if (time != null) clearTimeout(time);
  18. time = setTimeout(function () {
  19. for (var j = 0; j < a.length; j++) {
  20. if (j == i) {
  21. a[j].classList.add('active');
  22. b[j].classList.add('active');
  23. if (!phone) {
  24. b[j].classList.add('animation_downIn');
  25. b[j].classList.remove('animation_downOut');
  26. }
  27. } else {
  28. a[j].classList.remove('active');
  29. b[j].classList.remove('active');
  30. }
  31. }
  32. }, 200)
  33. }
  34. }(i);
  35. //控制鼠标移除时样式
  36. a[i].onmouseout = function (i) {
  37. return function () {
  38. if (time != null) clearTimeout(time);
  39. time = setTimeout(function () {
  40. a[i].classList.remove('active');
  41. b[i].classList.remove('active');
  42. b[i].classList.add('animation_downOut');
  43. b[i].classList.remove('animation_downIn');
  44. }, 200)
  45. }
  46. }(i);
  47. }
  48. }
  49. //pc 下层关闭控制
  50. function closeIcon() {
  51. var closeicon = document.getElementsByClassName('close_icon');
  52. for (var i = 0; i < closeicon.length; i++) {
  53. closeicon[i].onclick = function (i) {
  54. return function () {
  55. const controlDom = closeicon[i].parentNode.parentNode || closeicon[i].parentElement.parentElement;
  56. console.log(controlDom)
  57. controlDom.classList.remove('active');
  58. }
  59. }(i)
  60. }
  61. }
  62. //下层导航一级样式控制,二级显示控制
  63. function headerBoxOne(a, b) {
  64. if (phone) return;
  65. for (var i = 0; i < a.length; i++) {
  66. //控制鼠标悬浮时样式
  67. a[i].onmouseover = function (i) {
  68. return function () {
  69. for (var j = 0; j < a.length; j++) {
  70. if (j == i) {
  71. a[j].classList.add('active');
  72. b[j].classList.add('active');
  73. } else {
  74. a[j].classList.remove('active');
  75. b[j].classList.remove('active');
  76. }
  77. }
  78. }
  79. }(i);
  80. }
  81. }
  82. //二级样式控制,三级显示控制
  83. function headerBoxTwo(a, b) {
  84. if (phone) return;
  85. for (var i = 0; i < a.length; i++) {
  86. a[i].onmouseover = function (i) {
  87. return function () {
  88. const sep = a[i].className.split(" ")[2];
  89. for (var j = 0; j < a.length; j++) {
  90. if (j == i) {
  91. a[j].classList.add('active');
  92. b[j].classList.add('active');
  93. } else if (a[j].className.split(' ')[2] == sep) {
  94. a[j].classList.remove('active');
  95. b[j].classList.remove('active');
  96. }
  97. }
  98. }
  99. }(i)
  100. }
  101. }
  102. // header头部模块控制
  103. var headerLink = document.getElementsByClassName('header_link');
  104. var itemWraper = document.getElementsByClassName('item_wraper');
  105. var loopMenuWraper = document.getElementsByClassName('loop_menu_wraper');
  106. headerTop(headerLink, loopMenuWraper); //pc
  107. headerPhoneTop(itemWraper, loopMenuWraper); //phone
  108. // iconcontrol(); //phone左侧按钮控制
  109. closeIcon();
  110. //解决方案
  111. const listItemSoultion = document.getElementsByClassName('list_item_Soultion');
  112. const middleLoopMenu = document.getElementsByClassName('middle_loop_menu_Soultion');
  113. headerBoxOne(listItemSoultion, middleLoopMenu); //pc
  114. headerBoxPhoneOne(listItemSoultion, middleLoopMenu); //phone
  115. var listItemSol = document.getElementsByClassName('list_item_Solution_Three');
  116. var rightLoopMenuSolution = document.getElementsByClassName('right_loopMenu_Solution');
  117. headerBoxTwo(listItemSol, rightLoopMenuSolution); //pc
  118. headerBoxPhoneOne(listItemSol, rightLoopMenuSolution); //phone
  119. //产品中心
  120. const listItemProduct = document.getElementsByClassName('list_item_Product');
  121. const middleLoopMenuPro = document.getElementsByClassName('middle_loop_menu_Product');
  122. headerBoxOne(listItemProduct, middleLoopMenuPro); //pc
  123. headerBoxPhoneOne(listItemProduct, middleLoopMenuPro); //Phone
  124. const listItemPro = document.getElementsByClassName('list_item_Pro');
  125. const rightLoopMenuPro = document.getElementsByClassName('right_loopMenu_Pro');
  126. headerBoxTwo(listItemPro, rightLoopMenuPro); //pc
  127. headerBoxPhoneOne(listItemPro, rightLoopMenuPro); //phone
  128. //关于我们
  129. const listItemUs = document.getElementsByClassName('list_item_us');
  130. const rightLoopMenUs = document.getElementsByClassName('right_loopMenu_us');
  131. headerBoxOne(listItemUs, rightLoopMenUs);
  132. headerBoxPhoneOne(listItemUs, rightLoopMenUs); //Phone
  133. window.addEventListener('scroll', function () {
  134. if (phone) return;
  135. var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  136. if (scrollTop === 0) {
  137. header.className = 'header';
  138. } else {
  139. header.className = 'header active';
  140. }
  141. });
  142. //移动端样式
  143. //phone左侧按钮控制展开与闭合
  144. // function iconcontrol() {
  145. // const icon = document.getElementsByClassName('mobile_icon')[0];
  146. // const first_link = document.getElementsByClassName('first_link_wraper')[0];
  147. // const headerLink = document.getElementsByClassName('header_link');
  148. // const loopMenuWraper = document.getElementsByClassName('loop_menu_wraper');
  149. // icon.onclick = function() {
  150. // if (Array.from(first_link.classList).some(function(value) {
  151. // return value == 'none'
  152. // })) {
  153. // console.log(first_link.classList);
  154. // first_link.classList.remove('none')
  155. // } else {
  156. // for (j = 0; j < headerLink.length; j++) {
  157. // headerLink[j].classList.remove('active');
  158. // headerLink[j].children[0].children[1].src = '/cn/image/header/downwardArrow.svg'
  159. // loopMenuWraper[j].classList.remove('active');
  160. // }
  161. // first_link.classList.add('none')
  162. // }
  163. // }
  164. // }
  165. //首层导航控制
  166. function headerPhoneTop(a, b) {
  167. if (!phone) return
  168. for (var i = 0; i < a.length; i++) {
  169. //控制鼠标点击样式
  170. a[i].onclick = function (i) {
  171. return function () {
  172. if (!a[i].parentNode.className.split(" ").some(checkActive)) {
  173. // a[i].parentNode.children[0].children[1].src = '/cn/image/header/downwardArrowSelected.svg';
  174. for (var j = 0; j < a.length; j++) {
  175. if (j == i) {
  176. a[j].parentNode.classList.add('active');
  177. b[j].classList.add('active')
  178. } else {
  179. a[j].parentNode.classList.remove('active');
  180. b[j].classList.remove('active');
  181. // a[j].parentNode.children[0].children[1].src = '/cn/image/header/downwardArrow.svg';
  182. }
  183. }
  184. } else {
  185. // a[i].parentNode.children[0].children[1].src = '/cn/image/header/downwardArrow.svg';
  186. for (var j = 0; j < a.length; j++) {
  187. if (j == i) {
  188. a[j].parentNode.classList.remove('active');
  189. b[j].classList.remove('active');
  190. }
  191. }
  192. }
  193. }
  194. }(i);
  195. }
  196. }
  197. function checkActive(value) {
  198. return value == 'active';
  199. }
  200. //清除pc端初始默认的active
  201. clearActive();
  202. function clearActive() {
  203. console.log(phone);
  204. if (!phone) return;
  205. Array.from(document.getElementsByClassName('list_item')).map(function (item, index) {
  206. item.classList.remove('active');
  207. });
  208. Array.from(document.getElementsByClassName('right_loopMenu')).map(function (item, index) {
  209. item.classList.remove('active');
  210. });
  211. Array.from(document.getElementsByClassName(' middle_loop_menu')).map(function (item, index) {
  212. item.classList.remove('active');
  213. });
  214. const loopMenuWraper = document.getElementsByClassName('loop_menu_wraper');
  215. const first_link = document.getElementsByClassName('first_link_wraper')[0];
  216. const headerLink = document.getElementsByClassName('header_link');
  217. for (j = 0; j < headerLink.length; j++) {
  218. headerLink[j].classList.remove('active');
  219. headerLink[j].children[0].children[1].src = '/cn/image/header/downwardArrow.svg'
  220. loopMenuWraper[j].classList.remove('active');
  221. loopMenuWraper[j].classList.remove('animation_downOut');
  222. }
  223. first_link.classList.add('none')
  224. }
  225. //phone 下级层控制
  226. function headerBoxPhoneOne(a, b) {
  227. if (!phone) return
  228. for (var i = 0; i < a.length; i++) {
  229. a[i].parentNode.onclick = function (i) {
  230. return function () {
  231. if (!a[i].className.split(" ").some(checkActive)) {
  232. a[i].children[1].src = '/cn/image/header/downwardArrowSelected.svg';
  233. for (var j = 0; j < a.length; j++) {
  234. if (j == i) {
  235. a[j].classList.add('active');
  236. b[j].classList.add('active');
  237. stopPropagation();
  238. } else {
  239. a[j].classList.remove('active');
  240. b[j].classList.remove('active');
  241. a[j].children[1].src = '/cn/image/header/downwardArrow.svg';
  242. stopPropagation();
  243. }
  244. }
  245. } else {
  246. a[i].children[1].src = '/cn/image/header/downwardArrow.svg';
  247. for (var j = 0; j < a.length; j++) {
  248. if (j == i) {
  249. a[j].classList.remove('active');
  250. b[j].classList.remove('active');
  251. stopPropagation();
  252. }
  253. }
  254. }
  255. }
  256. }(i);
  257. }
  258. }
  259. function stopPropagation(e) {
  260. e = e || window.event;
  261. if (e.stopPropagation) { //W3C阻止冒泡方法
  262. e.stopPropagation();
  263. } else {
  264. e.cancelBubble = true; //IE阻止冒泡方法
  265. }
  266. }
  267. window.addEventListener('scroll', function () {
  268. var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  269. if (scrollTop === 0) {
  270. } else {
  271. if (phone) {
  272. const loopMenuWraper = document.getElementsByClassName('loop_menu_wraper');
  273. const first_link = document.getElementsByClassName('first_link_wraper')[0];
  274. const headerLink = document.getElementsByClassName('header_link');
  275. for (j = 0; j < headerLink.length; j++) {
  276. headerLink[j].classList.remove('active');
  277. // headerLink[j].children[0].children[1].src = '/cn/image/header/downwardArrow.svg'
  278. loopMenuWraper[j].classList.remove('active');
  279. }
  280. first_link.classList.add('none')
  281. } else {
  282. const loop_menu_wraper = document.getElementsByClassName('loop_menu_wraper');
  283. const header_link = document.getElementsByClassName('header_link');
  284. for (var i = 0; i < loop_menu_wraper.length; i++) {
  285. loop_menu_wraper[i].classList.remove('active')
  286. header_link[i].classList.remove('active')
  287. }
  288. }
  289. }
  290. });
  291. $('.contact_us_btn .btn').hover(function () {
  292. $('.f_img').css('display', 'block')
  293. $('.f_img_active').css('display', 'none')
  294. $(this).find('.f_img').css('display', 'none')
  295. $(this).find('.f_img_active').css('display', 'block')
  296. }, function () {
  297. $('.f_img').css('display', 'block')
  298. $('.f_img_active').css('display', 'none')
  299. // $(this).find('f_img').css('display', 'none')
  300. // $(this).find('f_img_active').css('display', 'block')
  301. });
  302. $('.tel').attr("data-clipboard-text", "010-63634201");
  303. var clipboard = new ClipboardJS('.tel');
  304. clipboard.on('success', function (e) {
  305. layer.msg("已复制成功: " + e.text);
  306. });
  307. clipboard.on('error', function (e) {
  308. layer.open({
  309. title: '提示',
  310. content: '您的浏览器可能不支持,请手动复制~'
  311. });
  312. });
  313. var clipboard = new ClipboardJS('.email_txt');
  314. clipboard.on('success', function (e) {
  315. layer.msg("已复制成功: " + e.text);
  316. });
  317. clipboard.on('error', function (e) {
  318. layer.open({
  319. title: '提示',
  320. content: '您的浏览器可能不支持,请手动复制~'
  321. });
  322. });
  323. });
  324. function jumpHtml(str, bool) { //第二个参数用来判断移动端是否跳转
  325. //stopPropagation();
  326. var ua = navigator.userAgent;
  327. isAndroid = /(?:Android)/.test(ua),
  328. isTablet = isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) //平板
  329. isPhone = /(?:iPhone)/.test(ua) || (isAndroid && /(?:Mobile)/.test(ua));
  330. console.log(isPhone)
  331. console.log(isTablet)
  332. if (!isPhone) {
  333. // stopPropagation();
  334. }
  335. if (isTablet || isPhone) {
  336. if (bool) {
  337. window.location.href = str;
  338. }
  339. } else {
  340. window.location.href = str;
  341. }
  342. }