common.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. function toThousands(num) {
  2. return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
  3. }
  4. $(function () {
  5. //回到顶部
  6. var win_h = $(window).height();
  7. $(window).on("scroll.totop",function(){
  8. var top = $(document).scrollTop();
  9. if(top>win_h){
  10. $(".toTop").addClass("showIn");
  11. }else{
  12. $(".toTop").removeClass("showIn");
  13. }
  14. })
  15. $(".toTop").click(function(){
  16. $("html,body").animate({"scrollTop":0});
  17. });
  18. //匹配最小高度
  19. $(".repository .list").css("min-height",$(".repository .category").innerHeight());
  20. //导航选中
  21. if (window.dataMark) {
  22. $("[data-mark='" + window.dataMark + "']").addClass("cur");
  23. }
  24. if (window.dataMark1) {
  25. $("[data-mark='" + window.dataMark1 + "']").addClass("cur");
  26. }
  27. $(document).on("touchstart",function(){});
  28. //nav-scroll
  29. $(document).on("scroll.nav", function () {
  30. var top = $(document).scrollTop();
  31. if (top > 100) {
  32. $(".header").addClass("slide");
  33. } else {
  34. $(".header").removeClass("slide");
  35. }
  36. })
  37. //second nav pc
  38. var $navBtn = $(".nav-ul li a");
  39. var $navCon = $(".nav-drop .container");
  40. var navTimer;
  41. $navBtn.on("mouseenter",function () {
  42. var $self = $(this);
  43. clearTimeout(navTimer);
  44. navTimer = setTimeout(function () {
  45. var index = $self.parent().index("li");
  46. var navConSelf = $navCon.eq(index);
  47. var conHtml = navConSelf.html().trim();
  48. if (conHtml) {
  49. navConSelf.stop().slideDown().siblings().stop().slideUp();
  50. } else {
  51. $navCon.stop().slideUp();
  52. }
  53. },200)
  54. })
  55. $(".nav-box").on("mouseleave", function () {
  56. $navCon.stop().slideUp();
  57. clearTimeout(navTimer);
  58. })
  59. //
  60. //second nav m
  61. $(".header .menu").on("click", function () {
  62. $(this).toggleClass("open");
  63. $(".m-nav-drop").slideToggle().toggleClass("open");
  64. })
  65. $(".m-nav-drop .added").on("click", function () {
  66. $(this).siblings(".added-value").slideToggle();
  67. })
  68. $(".m-nav-drop>ul a i").on("click",function(){
  69. var index = $(this).parent().index(".have");
  70. $(".second-nav ul").eq(index).show();
  71. $(".second-nav").addClass("open");
  72. return false;
  73. })
  74. $(".second-nav-back i").on("click",function(){
  75. $(".second-nav").removeClass("open");
  76. $(".second-nav ul").hide();
  77. return false;
  78. })
  79. //links
  80. $(".footer .links .choose").click(function () {
  81. $(this).find("ul").slideToggle();
  82. $(document).off("click.links");
  83. $(document).one("click.links", function () {
  84. $(".links .choose ul").slideUp();
  85. return false;
  86. })
  87. return false;
  88. })
  89. $(".footer .links .choose li").click(function () {
  90. var linkUrl= $(this).attr("data-url");
  91. $(this).parent().slideUp().siblings("span").html($(this).html()).attr("data-url",linkUrl);
  92. return false;
  93. })
  94. $(".links a").on("click",function(){
  95. var linkUrl = $(this).siblings(".choose").find("span").attr("data-url");
  96. window.open(linkUrl);
  97. })
  98. //search
  99. $(".footer .keywords a").click(function(){
  100. search_i();
  101. })
  102. $(document).on("keyup",function(e){
  103. if(e.keyCode == 13){
  104. search_i()
  105. }
  106. })
  107. function search_i(){
  108. var val = $(".footer .keywords input").val();
  109. if(val){
  110. window.open("/home/search?keywords="+val);
  111. }
  112. }
  113. //退出登录
  114. $(".header .user-login").hover(function(){
  115. $(this).find(".logout").stop().slideDown();
  116. },function(){
  117. $(this).find(".logout").stop().slideUp();
  118. })
  119. });
  120. //浏览器版本是否低于IE9及一下
  121. window.lessThenIE8 = function () {
  122. var UA = navigator.userAgent,
  123. isIE = UA.indexOf('MSIE') > -1,
  124. v = isIE ? /\d+/.exec(UA.split(';')[1]) : 'no ie';
  125. return v < 10;
  126. }();
  127. // 移动导航
  128. $('.mobileNav .menu').click(function (event) {
  129. var _this = $(this);
  130. if (_this.hasClass('open')) {
  131. _this.find('.menuList').slideUp('fast');
  132. _this.removeClass('open');
  133. } else {
  134. _this.addClass('open');
  135. _this.find('.menuList').slideDown('fast');
  136. }
  137. window.event ? window.event.cancelBubble = true : event.stopPropagation();
  138. })
  139. $('.menuItem').click(function (event) {
  140. let child = $(this).find('.menuChild');
  141. if (child.css('display') === 'block') {
  142. child.fadeOut();
  143. } else {
  144. child.fadeIn();
  145. $(this).siblings().find('.menuChild').fadeOut();
  146. }
  147. event.stopPropagation();
  148. })
  149. $('.mSearch').click(function () {
  150. event.stopPropagation();
  151. })
  152. $('.mSearch input').keydown(function (code) {
  153. console.log(code)
  154. if (code.keyCode == 13) {
  155. if (!$(this).val()) {
  156. alert('请填写搜索内容');
  157. return;
  158. }
  159. alert($(this).val())
  160. }
  161. })
  162. //pc导航
  163. $('.navItem').hover(function () {
  164. $(this).siblings().find('.childNav').hide();
  165. $(this).find('.childNav').fadeIn().parents('.navItem').siblings().find('.childNav').hide().find('.granNav').hide();
  166. }, function () {
  167. $(this).find('.childNav').hide();
  168. $(this).find('.granNav').hide()
  169. })
  170. //pc 三级
  171. $('.childNav>li').hover(function () {
  172. $(this).addClass('cur').siblings().removeClass('cur');
  173. $(this).find('.granNav').slideDown();
  174. }, function () {
  175. $(this).find('.granNav').slideUp();
  176. $(this).removeClass('cur').siblings().removeClass('cur');
  177. })