I'm using a variable font and would like to animate it using @keyframes on scroll and then not animate when the user stops scrolling.
I can make the animation work, however when you stop scrolling, the animation stops and snaps back to the starting position which makes it look very jumpy.
To make it more of a smooth finish, I'm wondering if there is a way that when the user stops scrolling, it is possible to get the current position of the animation and then complete that animation loop and then stop, instead of snapping immediately back to the starting position?
As i cannot load the variable font into a jsfiddle using @font-face, i've put it up here: http://slug.directory/GX/
Here is the js...
$(document).ready(function() {
var scrollTimerId;
$(window).scroll(function() {
if (!scrollTimerId)
$('body').addClass('scrolling');
clearTimeout(scrollTimerId);
scrollTimerId = setTimeout(function(){
$('body').removeClass('scrolling');
scrollTimerId = undefined;
},150);
});
});
and css...
@keyframes changewidth {
0% {
font-variation-settings: 'wght' 1;
}
100% {
font-variation-settings: 'wght' 100;
}
}
.scrolling {
animation-duration: 0.5s;
animation-name: changewidth;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: forwards;
}
body {
font-family: "AG GX", Helvetica, sans-serif;
font-weight: normal;
font-style: normal;
font-size: 2vw;
line-height: 2vw;
font-variation-settings: 'wght' 1;
height: 300vh;
}
div {
position: fixed;
}
Thanks in advance!