This video covers the structure of creating a sliding out menu, and explains how to adjust the animation as you desire.
Code snippet is attached below.
Snippet:
import wixAnimations from 'wix-animations';
import wixWindow from 'wix-window';
let navTimeline;
let screenSizeInterval;
$w.onReady(function () {
let open = false;
$w('#navOpen').onClick(() => {
if (open == false) {
screenSize();
screenSizeInterval = setInterval(screenSize, 700)
open = true;
} else {
clearInterval(screenSizeInterval);
navTimeline = wixAnimations.timeline().add($w('#nav'), { x: 0, duration: 300, easing: 'easeInOutCubic' }).play();
open = false;
}
})
function screenSize() {
wixWindow.getBoundingRect()
.then((windowSizeInfo) => {
let windowWidth = windowSizeInfo.window.width;
navTimeline = wixAnimations.timeline().add($w('#nav'), { x: -(windowWidth * 0.95), duration: 300, easing: 'easeInOutCubic' }).play();
});
}
});
Nice one!
wixWindow.getBoundingRect () allow you to get information about the screen.
Here it’s use to get the screen width size in pixels ( windowSizeInfo . window . width) so we know what the distance of entry and exit of the menu screen is.
Here you can learn more about it: https://www.wix.com/velo/reference/wix-window/getboundingrect
@jonathant I tried doing it but it doesnt work for me. When I resize the viewport, the container messes up. https://www.screencast.com/t/ozrAUyAjQ9T What have I done wrong? I tried changing the width of the Nav container to 100% or 100vw and it doesn’t change anything.
Any work arounds or fixes for this? I really like/want to use this slide out set up but it breaks when you drag the viewport like Liam’s video. It’s set to 100vw so I don’t understand why it would be doing it. Something to do with the negative margin?
Hey guys, did you find a manage to work around this error? Seems like a really good solution for the menu I am trying to build, depending on whether you got some feedback from the editor x team or someone else found a solution to this error.