init.js 2.2 KB

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