header.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. $(function() {
  2. // 判断用户现在使用的是什么平台
  3. $.ajax({
  4. url: getServerHttp() + '/getLoginUser',
  5. type: 'post',
  6. dataType: 'json',
  7. success: function(data) {
  8. var data = ajaxDataParames(data);
  9. if (data.success === "true" && data.loginUser.name) {
  10. var name = data.loginUser.name ? data.loginUser.name : '游客';
  11. var dom = '<li><a href="/web-back/view/frame/frame.html" target="_blank">' + name + '</a><span></span></li>';
  12. $('.nav-first-right ul').append(dom)
  13. } else if (data.success === "false" || !data.loginUser.name) {
  14. var dom = '<li><a href="/web-back/view/register/register.html" target="_blank">注册</a><span></span></li><li><a href="/web-back/login_back.html" target="_blank" style="color:#e22">登录</a></li>';
  15. $('.nav-first-right ul').append(dom)
  16. }
  17. },
  18. error: function() {
  19. console.log('请求错误')
  20. }
  21. });
  22. //功能
  23. $.fn.extend({
  24. //顶部浮动
  25. topNavPosition: function() {
  26. var _this = this;
  27. var _father = _this.parent();
  28. var _last = _this.find(".header-last-box");
  29. var _animate = true;
  30. $(window).scroll(function() {
  31. if ($(window).scrollTop() > 35 && _animate == true) {
  32. _father.animate({
  33. height: "60px"
  34. });
  35. _this.css({
  36. "box-shadow": "1px 1px 30px #999"
  37. })
  38. _this.animate({
  39. top: "-115px"
  40. });
  41. _last.animate({
  42. height: "60px"
  43. });
  44. _animate = false;
  45. }
  46. if ($(window).scrollTop() == 0) {
  47. _father.animate({
  48. height: "195px"
  49. });
  50. _this.css({
  51. "box-shadow": "0px 0px 0px #999"
  52. })
  53. _this.animate({
  54. top: "0"
  55. }, 300);
  56. _last.animate({
  57. height: "80px"
  58. });
  59. _animate = true;
  60. }
  61. })
  62. },
  63. //顶部下拉菜单
  64. topDropDownMwnu: function() {
  65. $(this).hover(function() {
  66. var _thisID = $(this).attr('id');
  67. $('.drop-down-menu').css({
  68. display: 'block'
  69. });
  70. $('.' + _thisID).css({
  71. display: 'block'
  72. }).siblings().css({
  73. display: 'none'
  74. })
  75. }, function() {
  76. $('.drop-down-menu').css({
  77. display: 'none'
  78. });
  79. });
  80. $('.drop-down-menu').hover(function() {
  81. $('.drop-down-menu').css({
  82. display: 'block'
  83. })
  84. }, function() {
  85. $('.drop-down-menu').css({
  86. display: 'none'
  87. })
  88. });
  89. },
  90. topSelectStyle: function() {
  91. var navSelect = $('.header-content-center li');
  92. var selectIndex = $(this).attr("data-selectIndex");
  93. for (var i = 0; i < navSelect.length; i++) {
  94. $(navSelect[selectIndex]).find('a').css({
  95. 'color': '#0cb46a'
  96. }).find('span').css({
  97. 'display': 'block'
  98. })
  99. }
  100. }
  101. });
  102. function topFun() {
  103. $('.header-nav-content-box').topNavPosition();
  104. $('.drop-down-but').topDropDownMwnu();
  105. $('.header').topSelectStyle();
  106. }
  107. topFun();
  108. })