Skip to content
Advertisement

Run a javascript function from HTML events

I’m working on a project that animate on page scroll. This is the element I want to animate.

JavaScript

This is my JavaScript

JavaScript

And this is my CSS

JavaScript

I need to run the function animateAfterPosition from the html. I expected to run the function with onscroll event, but it doesn’t work. So how can I do this?

Edit
I found that css attr() is only working with the content: property and I managed to do it with JavaScript

Advertisement

Answer

You need to add selector to toggle class the animation. And your current css doesn’t have enough height to make scrolling window. Here’s an simple snippet to run your function onload, update onscroll and toggling class.

JavaScript
JavaScript
JavaScript

Fiddle: https://jsfiddle.net/rafonzoo/phmg0u46/

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement