猎豆优选小程序

main.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. $(document).ready(function() {
  2. // Header Scroll
  3. $(window).on('scroll', function() {
  4. var scroll = $(window).scrollTop();
  5. if (scroll >= 50) {
  6. $('#header').addClass('fixed');
  7. } else {
  8. $('#header').removeClass('fixed');
  9. }
  10. });
  11. // Owl Carousel
  12. $("#owl-demo").owlCarousel({
  13. autoPlay : true,
  14. pagination: false,
  15. navigation : false
  16. });
  17. // Fancybox
  18. $('.work-box').fancybox();
  19. // Page Scroll
  20. var sections = $('section')
  21. nav = $('nav[role="navigation"]');
  22. $(window).on('scroll', function () {
  23. var cur_pos = $(this).scrollTop();
  24. sections.each(function() {
  25. var top = $(this).offset().top - 76
  26. bottom = top + $(this).outerHeight();
  27. if (cur_pos >= top && cur_pos <= bottom) {
  28. nav.find('a').removeClass('active');
  29. nav.find('a[href="#'+$(this).attr('id')+'"]').addClass('active');
  30. }
  31. });
  32. });
  33. nav.find('a').on('click', function () {
  34. var $el = $(this)
  35. id = $el.attr('href');
  36. $('html, body').animate({
  37. scrollTop: $(id).offset().top - 75
  38. }, 500);
  39. return false;
  40. });
  41. // Mobile Navigation
  42. $('.nav-toggle').on('click', function() {
  43. $(this).toggleClass('close-nav');
  44. nav.toggleClass('open');
  45. return false;
  46. });
  47. nav.find('a').on('click', function() {
  48. $('.nav-toggle').toggleClass('close-nav');
  49. nav.toggleClass('open');
  50. });
  51. });