Skip to content
This repository was archived by the owner on Jan 7, 2026. It is now read-only.

Commit 5d7a1cb

Browse files
committed
new wrapper
1 parent 5fc425a commit 5d7a1cb

File tree

4 files changed

+59
-42
lines changed

4 files changed

+59
-42
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-lenis",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"license": "MIT",
55
"type": "module",
66
"repository": {
@@ -31,7 +31,7 @@
3131
},
3232
"dependencies": {
3333
"@nuxt/kit": "^3.6.5",
34-
"@studio-freight/lenis": "^1.0.30"
34+
"@studio-freight/lenis": "1.0.27"
3535
},
3636
"devDependencies": {
3737
"@nuxt/devtools": "^0.8.5",

playground/pages/index.vue

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
<template>
2-
<div id="wrapper" ref="wrapper">
3-
<lenis
4-
id="test"
5-
ref="lenisRef"
6-
:options="vsOptions"
7-
@scroll="scrollEmitter"
8-
>
9-
<div>
10-
<h2>Index Page</h2>
11-
<p>Playground for lenis scroll plugin for nuxt</p>
12-
</div>
2+
<lenis
3+
id="wrapper"
4+
ref="lenisRef"
5+
:options="vsOptions"
6+
@scroll="scrollEmitter"
7+
@initiated="initiated"
8+
>
9+
<!-- <div id="content"> -->
10+
<div>
11+
<h2 @click="stop">STOP</h2>
12+
<h2 @click="start">START</h2>
13+
<p>Playground for lenis scroll plugin for nuxt</p>
14+
</div>
1315

14-
<div></div>
15-
<div></div>
16-
<div></div>
17-
</lenis>
18-
</div>
16+
<div></div>
17+
<div></div>
18+
<div></div>
19+
<!-- </div> -->
20+
</lenis>
1921
</template>
2022

2123
<script setup>
2224
import { ref, reactive, inject, watch, onMounted } from "vue";
2325
2426
const scrollState = inject("scrollState");
25-
const wrapper = ref(null);
2627
const lenisRef = ref(null);
28+
const lenisVs = ref(false);
2729
const vsOptions = reactive({
28-
content: "#test",
29-
// duration: 0.2,
30-
// direction: "Horizontal",
30+
wrapper: "#wrapper",
3131
touchMultiplier: 20,
3232
infinite: false,
3333
});
@@ -43,7 +43,16 @@ watch(vsOptions, (newVal) => {
4343
const scrollEmitter = (val) => {
4444
// console.log("scrollEmitter", val);
4545
};
46+
const stop = (val) => {
47+
console.log("lenisVs", lenisVs.value);
48+
lenisVs.value.stop();
49+
};
50+
const start = (val) => {
51+
console.log("lenisVs", lenisVs.value);
52+
lenisVs.value.start();
53+
};
4654
55+
const initiated = ({ lenis }) => (lenisVs.value = lenis);
4756
const changeOptions = () => {
4857
console.log("🐯 changing options");
4958
vsOptions.duration = vsOptions.duration > 5 ? 0.1 : 10;
@@ -55,17 +64,24 @@ onMounted(() => {
5564
</script>
5665

5766
<style>
58-
#test {
59-
min-height: 100%;
67+
/* #test {
6068
height: auto;
61-
}
62-
#test > div {
69+
} */
70+
#wrapper div {
6371
min-height: 50vh;
6472
margin-bottom: 300px;
65-
background: red;
73+
background: beige;
6674
width: 100%;
6775
}
6876
77+
#wrapper {
78+
max-height: 100vh;
79+
/* height: auto; */
80+
/* pointer-events: none; */
81+
}
82+
#content {
83+
height: auto;
84+
}
6985
.fixed {
7086
position: fixed;
7187
top: 100px;

src/runtime/components/lenis.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
2-
<div ref="lenisContent">
3-
<slot />
2+
<div ref="lenisWrapper">
3+
<div v-if="options.wrapper" ref="lenisContent"><slot /></div>
4+
<slot v-else />
45
</div>
56
</template>
67

@@ -24,6 +25,8 @@ export default defineComponent({
2425
const setLenis = inject("setLenis");
2526
const lenisVS = ref(0);
2627
const lenisRaf = ref(null);
28+
const mainContent = ref(null);
29+
const lenisWrapper = ref(null);
2730
const lenisContent = ref(null);
2831
2932
/**
@@ -46,15 +49,9 @@ export default defineComponent({
4649
4750
// On mounted set new Lenis instance
4851
onMounted(() => {
49-
if (lenisOptions.value.content) {
50-
lenisOptions.value.content = document.querySelector(
51-
lenisOptions.value.content
52-
);
53-
}
5452
if (lenisOptions.value.wrapper) {
55-
lenisOptions.value.wrapper = document.querySelector(
56-
lenisOptions.value.wrapper
57-
);
53+
lenisOptions.value.wrapper = lenisWrapper.value;
54+
lenisOptions.value.content = lenisWrapper.value.children[0];
5855
}
5956
initLenis();
6057
});
@@ -107,7 +104,7 @@ export default defineComponent({
107104
return {
108105
destroyLenis,
109106
initLenis,
110-
lenisContent,
107+
lenisWrapper,
111108
lenisVS,
112109
};
113110
},
@@ -121,6 +118,7 @@ html.lenis {
121118
122119
.lenis.lenis-smooth {
123120
scroll-behavior: auto !important;
121+
overflow: hidden;
124122
}
125123
126124
.lenis.lenis-smooth [data-lenis-prevent] {
@@ -134,4 +132,7 @@ html.lenis {
134132
.lenis.lenis-scrolling iframe {
135133
pointer-events: none;
136134
}
135+
#test {
136+
width: 90vw;
137+
}
137138
</style>

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,10 +1714,10 @@
17141714
resolved "https://registry.yarnpkg.com/@sindresorhus/merge-streams/-/merge-streams-2.2.1.tgz#82b5e1e135ef62ef8b522d6e7f43ad360a69f294"
17151715
integrity sha512-255V7MMIKw6aQ43Wbqp9HZ+VHn6acddERTLiiLnlcPLU9PdTq9Aijl12oklAgUEblLWye+vHLzmqBx6f2TGcZw==
17161716

1717-
"@studio-freight/lenis@^1.0.30":
1718-
version "1.0.35"
1719-
resolved "https://registry.yarnpkg.com/@studio-freight/lenis/-/lenis-1.0.35.tgz#039d1064363306f6554b8d676421db647dffd770"
1720-
integrity sha512-dduQqZERC5EaJSVGBoCt2WdPFQlr39zFewkQxvJcYZrMl1aVTPPIQCnZMqIjl4KZBQIL3kIXes+HP22T9XVh4w==
1717+
"@studio-freight/lenis@1.0.27":
1718+
version "1.0.27"
1719+
resolved "https://registry.yarnpkg.com/@studio-freight/lenis/-/lenis-1.0.27.tgz#1a333e192efa1a036074f7dcffba847d4c45f6d1"
1720+
integrity sha512-1I6EaWR9rxdFjIJtF52CtETJt9ngfY4AjawrJY5pLxCvHa/lQZ+1v2gTUntwNZkuks6E2It6YEXV6jnpnCZFjA==
17211721

17221722
"@trysound/sax@0.2.0":
17231723
version "0.2.0"

0 commit comments

Comments
 (0)