sb-admin-2.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function($) {
  2. "use strict"; // Start of use strict
  3. // Toggle the side navigation
  4. $("#sidebarToggle, #sidebarToggleTop").on('click', function(e) {
  5. $("body").toggleClass("sidebar-toggled");
  6. $(".sidebar").toggleClass("toggled");
  7. if ($(".sidebar").hasClass("toggled")) {
  8. $('.sidebar .collapse').collapse('hide');
  9. };
  10. });
  11. // Close any open menu accordions when window is resized below 768px
  12. $(window).resize(function() {
  13. if ($(window).width() < 768) {
  14. $('.sidebar .collapse').collapse('hide');
  15. };
  16. // Toggle the side navigation when window is resized below 480px
  17. if ($(window).width() < 480 && !$(".sidebar").hasClass("toggled")) {
  18. $("body").addClass("sidebar-toggled");
  19. $(".sidebar").addClass("toggled");
  20. $('.sidebar .collapse').collapse('hide');
  21. };
  22. });
  23. // Prevent the content wrapper from scrolling when the fixed side navigation hovered over
  24. $('body.fixed-nav .sidebar').on('mousewheel DOMMouseScroll wheel', function(e) {
  25. if ($(window).width() > 768) {
  26. var e0 = e.originalEvent,
  27. delta = e0.wheelDelta || -e0.detail;
  28. this.scrollTop += (delta < 0 ? 1 : -1) * 30;
  29. e.preventDefault();
  30. }
  31. });
  32. // Scroll to top button appear
  33. $(document).on('scroll', function() {
  34. var scrollDistance = $(this).scrollTop();
  35. if (scrollDistance > 100) {
  36. $('.scroll-to-top').fadeIn();
  37. } else {
  38. $('.scroll-to-top').fadeOut();
  39. }
  40. });
  41. // Smooth scrolling using jQuery easing
  42. $(document).on('click', 'a.scroll-to-top', function(e) {
  43. var $anchor = $(this);
  44. $('html, body').stop().animate({
  45. scrollTop: ($($anchor.attr('href')).offset().top)
  46. }, 1000, 'easeInOutExpo');
  47. e.preventDefault();
  48. });
  49. })(jQuery); // End of use strict