Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /*
  2. * Create a new method with passed 3 arguments to switch fullpage.js
  3. */
  4. const switchFullPage = switcher.bind(null, trackWindowSizes,fullpageInit, fullpageDestroy);
  5.  
  6. /*
  7. * Track window changes to disable on small screens
  8. */
  9. $(window).on('resize', switchFullPage);
  10.  
  11. /*
  12. * Initialize our switcher
  13. */
  14. switchFullPage();
  15.  
  16. /*
  17. * Initialize fullpage.js only when it is not active
  18. */
  19. function fullpageInit() {
  20. if (!fullpageIsActive()) {
  21. $('#main').fullpage({
  22. anchors: ['page-1', 'page-2', 'page-3', 'page-4', 'page-5', 'page-6'],
  23. menu: '#slider-nav',
  24. scrollingSpeed: 1200,
  25. onLeave: function(index, nextIndex, direction){
  26. App.prototype.sectionContentParallax(index, nextIndex, direction);
  27. }
  28. });
  29.  
  30. location.hash = '';
  31. }
  32. }
  33.  
  34. /*
  35. * Destroy fullpage.js only if it is active
  36. */
  37. function fullpageDestroy() {
  38. if (fullpageIsActive()) {
  39. $.fn.fullpage.destroy('all');
  40. }
  41. }
  42.  
  43. /*
  44. * Check if fullpage.js is initialized
  45. */
  46. function fullpageIsActive () {
  47. return $( 'html' ).hasClass( 'fp-enabled' );
  48. }
  49.  
  50. /*
  51. * Check if window is small
  52. */
  53. function trackWindowSizes () {
  54. let w = window.matchMedia('(min-width: 780px)').matches,
  55. h = window.matchMedia('(min-height: 600px)').matches;
  56. return w && h;
  57. }
  58.  
  59. /*
  60. * Takes 3 arguments of type function,
  61. * first one is condition that return true or false
  62. * second one is what to do when condition returns true
  63. * third is what to do if condition false
  64. */
  65. function switcher( condition, resolve, reject ) {
  66. const state = condition();
  67. if ( state ) {
  68. resolve();
  69. } else {
  70. reject();
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement