I am having a problem knowing how to correctly write these variables and then placing them into animate.
var findCanvasMarginTop = ((100vh - 120) - cvsH) / 2;
var newCanvasMargin = findCanvasMarginTop + "px", 0, 0, 0;
var deployCanvasMargin = {'margin' : newCanvasMargin};
$('#text__menu--show').click(function () {
$('#canvas__container').animate(deployCanvasMargin, 100);
});
Whenever I do this or variations of this my code fails to load.
I am finding the the margin between an element on my page and the top of the window.
Then I am creating the margins adding in the margin I found in the first variable and setting the other 3 margins to 0 (as the only margin required to change is the top margin).
Then I am creating deployCanvasMargin which is the css, then in animate I add in the variable.
I thought this would effectively make the outcome of animate this:
$('#canvas__container').animate({'margin' : 50px, 0, 0, 0}, 100);
(Assuming 50px is the margin found)
Edit: I found another issue after the answer here helped me fix my animate issue. You can't have 100vh in the math. I need to create a variable that finds the viewport height and use that, not the css 100vh. Silly me :)
For anyone who has this same issue and is pretty inexperienced like me, I solved that additional issue by doing this
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
Then changing the first variable to this
var findCanvasMarginTop = ((h - 120) - cvsH) / 2;
{'margin' : 50px, 0, 0, 0}is not valid JS