Coder Social home page Coder Social logo

LocomotiveScroll methods about potiah HOT 4 CLOSED

cmarcelly avatar cmarcelly commented on August 20, 2024
LocomotiveScroll methods

from potiah.

Comments (4)

somespecialone avatar somespecialone commented on August 20, 2024

Hi! You can access instance of the LocomotiveScroll with scroll property.

const { potiah } = usePotiah()

potiah.scroll.destroy()
// anything you want to

from potiah.

cmarcelly avatar cmarcelly commented on August 20, 2024

Thank you, I'm able to access the instance but it looks that some methods are missing.

I'm working in a Nuxt 3 environment.

Here is the full list : https://scroll.locomotive.ca/docs/#/methods

It looks like start() and stop() methods for example are not available.

Or maybe I'm doing something wrong...

Also, It's weird I cannot run the scrollTo() method in the onMounted hook. But it works on click event... Here is my code:

<template>
    <section>
        <div class="section1">
			<h1>Section 1</h1>
			<button @click="potiah.scrollTo('.section2')">Click</button>
		</div>
		<div class="section2">
			<h1>
				Section 2
			</h1>
		</div>
	</section>
</template>

<script lang="ts" setup>
	import { usePotiah } from 'potiah'

	const { potiah } = usePotiah()

	onMounted(() => {
		requestAnimationFrame(() => {
			potiah.scrollTo(100)
		});
	})
</script>

<style scoped>
	.section1 {
		height: 100dvh;
		background: green;
	}

	.section2 {
		height: 100dvh;
		background: red;
	}
</style>

Thank you very much!

from potiah.

somespecialone avatar somespecialone commented on August 20, 2024

My bad - I missed the scroll property access in the previous message (already fixed).
To access the LocomotiveScroll instance, you need to run your code after scroll is ready. scrollTo will not work in onMounted in your example because LocomotiveScroll is not created yet (there is no guarantee even in raf callback).
You can look there how to do it.
To clarify, all the methods you are looking for are on the scroll property.

from potiah.

cmarcelly avatar cmarcelly commented on August 20, 2024

Perfect! Thank you so much it's works fine now and I understand better.

Really great job!

from potiah.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.