Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for svelte #4552

Open
TKTheTechie opened this issue May 17, 2023 · 6 comments
Open

Support for svelte #4552

TKTheTechie opened this issue May 17, 2023 · 6 comments

Comments

@TKTheTechie
Copy link

Are there plans to create a fullPage.js svelte component/plugin?

@alvarotrigo
Copy link
Owner

It'd be great to have one!
I haven't used Svelte personally so I'd need to research that a bit more.

But happy to get any help / PR ;)

@alvarotrigo
Copy link
Owner

alvarotrigo commented May 18, 2023

You can try using it this way for now?

<script>
  import { onMount, onDestroy } from 'svelte';

  export let options = {};

  let fullpage;

  onMount(() => {
    import('fullpage.js').then((module) => {
      fullpage = new module.default('#fullpage', options);
    });

    return () => {
      if (fullpage) {
        fullpage.destroy();
      }
    };
  });

  onDestroy(() => {
    if (fullpage) {
      fullpage.destroy();
    }
  });
</script>

<div id="fullpage">
  <slot />
</div>

<style>
  #fullpage {
    height: 100vh;
  }
</style>

@alvarotrigo
Copy link
Owner

alvarotrigo commented May 18, 2023

Usage:

<script>
  import FullPageWrapper from './FullPageWrapper.svelte';

  const fullpageOptions = {
    // Configure fullPage.js options here
  };
</script>

<FullPageWrapper {options}>
  <!-- Add your sections here -->
  <div class="section">Section 1</div>
  <div class="section">Section 2</div>
  <div class="section">Section 3</div>
</FullPageWrapper>

<style>
  .section {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
  }
</style>

@TKTheTechie
Copy link
Author

TKTheTechie commented May 18, 2023

Thanks. That works for me... slight change to your code:


<script>
  import { onMount, onDestroy } from 'svelte';
  import * as fullpage from 'fullpage.js';

  export let options = {};

  let fp;

  onMount(() => {
		fp = new fullpage('#fullpage', opts);
  });

  onDestroy(() => {

      fp.destroy();
    });
</script>

<div id="fullpage">
  <slot />
</div>

<style>
  #fullpage {
    height: 100vh;
  }
</style>

@alvarotrigo
Copy link
Owner

Awesome to hear!
Thanks for the fix! ;)

@TKTheTechie
Copy link
Author

The only challenge is that I can't appear to get the callback functions to trigger - example:

	fp = new fullpage('#fullpage', {
			onSlideLeave: (section, origin, destination, direction, trigger) => {
				console.log('Slide ' + destination);
			},
			anchors: ['Home', 'Resume', 'Blog'],
		});

The function will never trigger. Apart from that it appears to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants