How can I play a CSS animation only when it appears in the viewpoint?

The following example makes a CSS animation run only when it is in the user’s field of view, which is achieved, for example, by scrolling. Thereby an image becomes visible, which results in a drawn line.

The drawn line already exists as an image. By CSS this is completely hidden at the beginning and then slowly visible, so that the effect of a line drawn from top to bottom is created.

<div class="contain-element">
<img class="prints" src="/line.png" alt="Linie">
<span class="cover"></span>
.contain-element {
     position: relative;
     text-align: center;
.cover {
     position: absolute;
     left: 0;
     background: #fff;
     height: 1000px;
     width: 1420px;
@keyframes walk {
     to {
           transform: translateY(675px);
  jQuery ( function($) {
        if ($('.contain-element').isOnScreen()) {
      $(".cover").css("animation","walk 4s steps(28, end) forwards");
        } else {
            // The element is NOT visible, do something else

$.fn.isOnScreen = function(){
    var win = $(window);
    var viewport = {
        top : win.scrollTop(),
        left : win.scrollLeft()
    viewport.right = viewport.left + win.width();
    viewport.bottom = + win.height();
    var bounds = this.offset();
    bounds.right = bounds.left + this.outerWidth();
    bounds.bottom = + this.outerHeight();
    return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < || > bounds.bottom)); 
} );
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.
  • Developed 2023
  • CMS WordPress
  • Status Completed

Just a Web-Developer

Creating a developer’s own website is always a big challenge. You want to integrate all the cool features and show all your skills. Therefore, it is rather called here to make cutbacks and to put the information in the foreground. I hope this is halfway successful here.
To add value, I’ve taken the „Helpful Code Snippets“ element form my old website and integrated a search function for them.

  • Developed 2022
  • CMS WordPress
  • Status Completed

Tatort Ruhrpott

A few years ago I had the idea for a photo project. I wanted to photograph crime scenes from the Ruhr region and show how these places look today. During the Corona Pandemic 2021, I started taking the photos and at the beginning of 2022, I started implementing the corresponding website.

  • Developed 2018
  • CMS WordPress
  • Status Completed

CMS Geek

CMS Geek was a website project that I started in 2018 and was supposed to introduce users to the functions of WordPress through explanatory videos. In addition to a blog that informed about the latest news about WordPress and Joomla, there were also helpful code solutions to common WordPress, html and CSS problems.

Due to the lack of time to produce more explainer videos, I discontinued this project in spring 2023. I have taken over the code snippets for Just-a-Web-Developer, updated them and will continue to expand them.