Hello, so, I would like tu put in my website that function :
On eacg scroll, the animated element performs it’s animation. With this code, it is supposed to do it every time it appears on the page, and not once the first time you pass on.
But I can’t seem to make it work… If somebody can’t teach me !
I make an html element on Wix editor with this html code :
<style>
h2{
margin: 0;
padding: 10px; 0
text-align: center;
text-transform: uppercase;
letter-spacing: 0px;
font-size:18px
}
.container{
min-height: 300px;
display:flex;
justify-content:center;
align-items:center;
}
.inner-content{
display:flex;
justify-content:center;
align-items:center;
width:200px;
height:300px;
}
.box_1{
align-self: flex-end;
opacity: 0.5;
-webkit-transform: translateY(-100px);
-ms-transform: translateY(-100px);
transform: translateY(-100px);
overflow: hidden;
-webkit-transition: opacity 0.5s,-webkit-transform 0.7s;
transition: opacity 0.5s,-webkit-transform 0.7s;
-o-transition: opacity 0.5s,transform 0.7s;
transition: opacity 0.5s,transform 0.7s;
transition: opacity 0.5s,transform 0.7s,-webkit-transform 0.7s;
margin-bottom: 20px;
}
.box_1.animated{
opacity: 1;
-webkit-transform: translateY(0px);
-ms-transform: translateY(0px);
transform: translateY(0px);
}
</style>
<div class="container">
<div class="inner-content">
<div class="box_1"><h2>TEST</h2><p>Test test test</p></div>
</div>
</div>
And, on Velo I put this code on my masterPage.js after I install the npm package (jquery, @type/jquery, jsdom and punycode)=
import $ from "jquery";
var jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM();
const { document } = (new JSDOM('')).window;
global.document = document;
const punycode = require('punycode');
var $animation_elements = $('.box1');
var $window = $(window);
function check_if_in_view() {
var window_height = $window.height();
var window_top_position = $window.scrollTop();
var window_bottom_position = (window_top_position + window_height);
$.each($animation_elements, function() {
var $element = $(this);
var element_height = $element.outerHeight();
var element_top_position = $element.offset().top;
var element_bottom_position = (element_top_position + element_height);
if ((element_bottom_position >= window_top_position) &&
(element_top_position <= window_bottom_position)) {
$element.addClass('animated');
} else {
$element.removeClass('animated');
}
});
}
$window.on('scroll resize', check_if_in_view);
$window.trigger('scroll');
But, when I preview my result, I have this error message :
Cannot find module 'punycode' in 'public/pages/masterPage.js' (in red)
Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
Loading the code for the Projet Naegari page. To debug this code, open amch9.js in Developer Tools.
I think i was wrong on my html element… But in truth, i have no idea
If someone can help me it will be great !
Or if someone have another solution to anime an elements everytime you scroll in (and not juste once like the default effect in Wix) I take it
Thank a lot