extra_fab.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Floating action buttons
  4. *
  5. * Demo JS code for extra_fab.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var FloatingActionButton = function() {
  11. //
  12. // Setup module components
  13. //
  14. // FAB
  15. var _componentFab = function() {
  16. if (!$().stick_in_parent) {
  17. console.warn('Warning - sticky.min.js is not loaded.');
  18. return;
  19. }
  20. // Add bottom spacing if reached bottom,
  21. // to avoid footer overlapping
  22. // -------------------------
  23. $(window).on('scroll', function() {
  24. if($(window).scrollTop() + $(window).height() > $(document).height() - 40) {
  25. $('.fab-menu-bottom-left, .fab-menu-bottom-right').addClass('reached-bottom');
  26. }
  27. else {
  28. $('.fab-menu-bottom-left, .fab-menu-bottom-right').removeClass('reached-bottom');
  29. }
  30. });
  31. // Initialize sticky button
  32. $('#fab-menu-affixed-demo-left, #fab-menu-affixed-demo-right').stick_in_parent({
  33. offset_top: 20
  34. });
  35. };
  36. //
  37. // Return objects assigned to module
  38. //
  39. return {
  40. init: function() {
  41. _componentFab();
  42. }
  43. }
  44. }();
  45. // Initialize module
  46. // ------------------------------
  47. document.addEventListener('DOMContentLoaded', function() {
  48. FloatingActionButton.init();
  49. });