init.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. $(window).scroll(function() {
  2. var hd=$('header').height()
  3. if($(this).scrollTop() > $('header').offset().top) {
  4. $('header').addClass('nav_fx')
  5. $('.content').css('margin-top',hd+'px')
  6. }
  7. if($(this).scrollTop() <= hd) {
  8. $('header').removeClass('nav_fx')
  9. $('.content').css('margin-top','')
  10. }
  11. })
  12. var getSize = function() {
  13. var client_w=document.documentElement.clientWidth
  14. if(client_w>1000){
  15. document.body.style.fontSize=12+'px'
  16. }
  17. if(client_w>=750&&client_w<1000){
  18. document.body.style.fontSize=10+'px'
  19. }
  20. if(client_w<750&&client_w>=650){
  21. document.body.style.fontSize=8+'px'
  22. }
  23. if(client_w<650&&client_w>=400){
  24. document.body.style.fontSize=6+'px'
  25. }
  26. if(client_w<400&&client_w>=360){
  27. document.body.style.fontSize=5+'px'
  28. }
  29. if(client_w<360){
  30. document.body.style.fontSize=4+'px'
  31. }
  32. document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
  33. var hg=document.documentElement.clientHeight-$('header').height()
  34. $('.bar_content').height(hg)
  35. }
  36. window.onload=function(){
  37. getSize();
  38. }
  39. $(document).ready(function() {
  40. getSize();
  41. $(window).resize(function() {
  42. getSize();
  43. });
  44. })
  45. $(function() {
  46. var mySwiper = new Swiper('.swiper-container', {
  47. loop:true,
  48. pagination: {
  49. el: '.swiper-pagination',
  50. clickable: true
  51. },
  52. autoplay:{
  53. delay:2000,
  54. stopOnLastSlide:false,
  55. disableOnInteraction:true
  56. }
  57. })
  58. });
  59. $(document).ready(function() {
  60. //加载时隐藏子菜单
  61. $('li ul').hide();
  62. //不包含子菜单时鼠标指针和项目图标
  63. $('li:not(:has(ul))')
  64. .css({
  65. 'cursor': 'default'
  66. });
  67. //包含子菜单时鼠标指针和项目图标
  68. $('li:has(ul)')
  69. .css({
  70. 'cursor': 'pointer'
  71. });
  72. //单击含子菜单的项
  73. $('li:has(ul)').children('p').click(function(event) {
  74. if(this == event.target) {
  75. if($(this).siblings('ul').is(':hidden')) {
  76. $(this)
  77. .siblings('ul').show();
  78. $(this).children('span').text('-')
  79. } else {
  80. $(this)
  81. .siblings('ul').hide();
  82. $(this).children('span').text('+')
  83. }
  84. }
  85. })
  86. $('#rtTop').click(function(e) {
  87. e.preventDefault();
  88. $('html ,body').animate({
  89. scrollTop: 0
  90. }, 300);
  91. })
  92. })
  93. $('.bar_content').click(function() {
  94. if($('.bar_content').hasClass('active')) {
  95. $('.bar_content').removeClass('active')
  96. }
  97. })
  98. $('.icon_left').click(function() {
  99. $('.bar_content').toggleClass('active')
  100. $('.bar_content').on('touchmove',function(e){e.preventDefault()})
  101. })