skip to Main Content

I want on scroll down, that the images are moving up a bit, like on this website:

example site (digital does)

Images example

Down the website on digitaldoes you can see what i mean. The images are moving up a bit if you scroll down. Is it maby a lazy-load with images that are fading in or an animation where the images moving for example 5px up?

Here is a: jsfiddle updated!!!

$(document).ready(function () {
    
    $(".img-scroll").css("display", "none");
    
    $(window).scroll(function() {
        $( ".img-scroll" ).addClass("animate");
        $( ".img-scroll" ).css("display", "block");
        console.log("Hey");
    });
    
});
.img-scroll {
  -moz-transition: top 10s;
  transition: top 10s;
}


.img-scroll.animate {
  top: 5px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row">
  <header class="arbeiten">
    <h2>{ Logos }</h2>
  </header>
</div>

<div id="links">

  <div class="row">

    <div class="col-xxl-1"></div>

    <div class="col-12 col-md-6 col-lg-4 col-xxl-5">
      <div class="card shadow-sm first-image">
        <a href="https://www.fillmurray.com/1000/1000" title="Test - Logo #1">
          <img src="https://www.fillmurray.com/300/150" alt="Test - Logo #1" class="card-img-top logo-hover">
        </a>

        <div class="card-body">
          <p class="card-text">Test - Logo #1</p>
          <div class="d-flex justify-content-between align-items-center"></div>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-6 col-lg-4 col-xxl-5">
      <div class="card shadow-sm">
        <a href="https://www.fillmurray.com/1000/1000" title="Test - Logo #2">
          <img src="https://www.fillmurray.com/300/150" alt="Test - Logo #2" class="card-img-top logo-hover">
        </a>
        <div class="card-body">
          <p class="card-text">Test - Logo #2</p>
          <div class="d-flex justify-content-between align-items-center"></div>
        </div>
      </div>


      <div class="col-12 col-md-6 col-lg-4 col-xxl-5 img-scroll">
        <div class="card shadow-sm first-image">
          <a href="https://www.fillmurray.com/1000/1000" title="Test - Logo #3">
            <img src="https://www.fillmurray.com/300/150" alt="Test - Logo #3" class="card-img-top logo-hover">
          </a>

          <div class="card-body">
            <p class="card-text">Test - Logo #3</p>
            <div class="d-flex justify-content-between align-items-center"></div>
          </div>
        </div>
      </div>

      <div class="col-xxl-1"></div>
      <div class="col-xxl-1"></div>

    </div>
    
    
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

I hope, someone can help me…

7

Answers


  1. They have build the gallery with gridster and scrollmagic. Scrollmagic lets you do all kind of things when scrolling.

    you can checkout the package at https://scrollmagic.io

    Login or Signup to reply.
  2. The animation on the site that you provided is triggered when the load event on the images is emitted. The load event is emitted when an image has completed loading. This is combined with lazy loading to load the images as you scroll down on the page.

    To implement something like this, you need to enable lazy loading for the images and listen for a load event on them. When the load event is emitted, use Javascript to complete the animation.

    The javascript would look something like this:

    $(".img-scroll").one("load", () => {
        // do animation here
    })
    

    Just make sure the images have lazy loading enabled by setting their loading attribute to lazy

    Login or Signup to reply.
  3. there is a very good library for scroll effect called AOS.I linked it down here
    it .You can find setup guide at the end of the page. Just add those styles to your image or any other html tag!. Make sure that you check it out.

    link to AOS library

    Login or Signup to reply.
  4. The most important step is to check if an <img> element is entering the current viewport.

    We can use the Intersection Observer API.

    const options = {
      rootMargin: "0px",
      threshold: 0.5
    };
    
    const inViewPortObserver = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          let target = entry.target;
          let dataSrc = target.getAttribute('data-src');
          target.src = dataSrc;
          target.classList.replace('lazyload', 'lazyloaded');
        }
      });
    }, options);
    

    By adjusting the threshold value we can define when the intersecting value returns true:
    E.g treshold:0.5 => element is intersection if 50% of it’s height is in viewport.

    Now we can define a callback:
    if(entry.isIntersecting){}
    If element is in viewport – set the src attribute from data-src and toggle css classes from ‘lazyload’ to ‘lazyloaded’.

    Most lazyload libraries use a similar syntax or api concept like this:

    <img data-src="https://www.fillmurray.com/480/480" class="lazyload">
    

    The actual image src/URL is defined by a data attribute: data-src.
    Lazy loading can significantly improve the overall performance and user experience by loading images only if they are really required.

    The animation is done by toggling between css classes:
    E.g .lazyload (not loaded yet) and lazyloaded (loaded)

    .lazyload {
        opacity: 0;
        transform: translateY(100%);
    }
    
    .lazyloaded {
        opacity: 1;
        transform: translateY(0%);
    }
    

    Simple Example: using js IntersectionObserver()

    const options = {
      rootMargin: "0px",
      threshold: 0.5
    };
    
    const inViewPortObserver = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          let target = entry.target;
          let dataSrc = target.getAttribute('data-src');
          target.src = dataSrc;
          target.classList.replace('lazyload', 'lazyloaded');
        }
      });
    }, options);
    
    const images = document.querySelectorAll('.lazyload');
    images.forEach(function(img, i) {
      inViewPortObserver.observe(img);
    })
    * {
      box-sizing: border-box
    }
    
    header {
      margin-bottom: 40vmin;
    }
    
    main {
      padding-bottom: 50em;
    }
    
    section {
      margin-bottom: 20em;
    }
    
    .row {
      display: flex;
    }
    
    .row>* {
      flex: 1;
    }
    
    .card-img-top {
      transition: 2s;
    }
    
    .lazyload {
      opacity: 0;
      transform: translateY(100%);
    }
    
    .lazyloaded {
      opacity: 1;
      transform: translateY(0%);
    }
    
    img {
      aspect-ratio: 2/1;
      display: block;
      background-color: #ccc;
      width: 100%;
      max-width: 100%;
      object-fit: cover;
      object-position: 50% 50%;
    }
    <div class="row">
      <header class="arbeiten">
        <h2>{ Logos }</h2>
        <p>Please scroll down …</p>
      </header>
    </div>
    
    <main>
      <section>
        <div class="row">
          <figure>
            <img data-src="https://www.fillmurray.com/480/480" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
          <figure>
            <img data-src="https://www.fillmurray.com/300/150" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
        </div>
    
        <div class="row">
          <figure>
            <img data-src="https://www.fillmurray.com/300/200" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
          <figure>
            <img data-src="https://www.fillmurray.com/200/300" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
          <figure>
            <img data-src="https://www.fillmurray.com/400/240" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
        </div>
      </section>
    
      <section>
        <div class="row">
          <figure>
            <img data-src="https://www.fillmurray.com/320/240" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
    
          <figure>
            <img data-src="https://www.fillmurray.com/300/150" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
          <figure>
            <img data-src="https://www.fillmurray.com/333/111" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
          <figure>
            <img data-src="https://www.fillmurray.com/444/333" alt="Test - Logo #1" class="lazyload card-img-top logo-hover">
          </figure>
        </div>
      </section>
    </main>

    Example 2: observe a parent element and lazyload images

    The main difference: we’re observing viewport intersections for parent elements like the .card class.

    const options = {
      rootMargin: "0px",
      threshold: 0.1
    };
    
    const inViewPortObserver = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          let target = entry.target;
          let img = target.querySelector('img');
          let dataSrc = img.getAttribute('data-src');
          img.src = dataSrc;
          target.classList.add('inViewPort');
        }
      });
    }, options);
    
    const cards = document.querySelectorAll('.card');
    cards.forEach(function(card, i) {
      inViewPortObserver.observe(card);
    })
    * {
      box-sizing: border-box
    }
    
    header {
      margin-bottom: 60vmin;
    }
    
    main {
      padding-bottom: 50em;
    }
    
    section {
      margin-bottom: 20em;
    }
    
    .row {
      display: flex;
      gap: 1em;
    }
    
    .row>* {
      flex: 1;
    }
    
    .card {
      transition: 2s;
      transform: translateY(100%);
      border: 2px solid red;
      opacity: 0;
    }
    
    
    /** optional sibling delay */
    
    .row .card:nth-of-type(2) {
      transition-delay: 0.5s;
    }
    
    .row .card:nth-of-type(3) {
      transition-delay: 0.75s;
    }
    
    .row .card:nth-of-type(4) {
      transition-delay: 1s;
    }
    
    .row .card:nth-of-type(5) {
      transition-delay: 1.25s;
    }
    
    .row .card:nth-of-type(6) {
      transition-delay: 1.5s;
    }
    
    .inViewPort {
      opacity: 1;
      transform: translateY(0%);
    }
    
    img {
      aspect-ratio: 2/1;
      display: block;
      background-color: #ccc;
      width: 100%;
      max-width: 100%;
      object-fit: cover;
      object-position: 50% 50%;
    }
    <div class="row">
      <header class="arbeiten">
        <h2>{ Logos }</h2>
        <p>Please scroll down …</p>
      </header>
    </div>
    
    <main>
      <section>
        <div class="row row1">
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/480/480" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/150" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/222" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/247" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          
          
        </div>
      </section>
    
    
      <section>
        <div class="row row2">
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/320/240" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/111" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/112" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
        </div>
      </section>
    
    
      <section>
        <div class="row row2">
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/320/240" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/111" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
          <div class="card">
            <a href="#">
              <img data-src="https://www.fillmurray.com/300/112" alt="" class="lazyload card-img-top logo-hover">
            </a>
          </div>
        </div>
      </section>
    Login or Signup to reply.
  5. I am using TweenMax.min.js, TimelineMax.min.js, ScrollMagic.min.js

    • List item
    const tl = new TimelineMax();
    const tl2 = new TimelineMax();
    const controller = new ScrollMagic.Controller();
    
    tl.from('#first-fig', .3, {y:200, opacity: 0});
    tl.from('#second-fig', .3, {scale: 0}, "=-.5");
    tl.from('#third-fig', .3, {y:200, opacity: 0});
    
    tl2.from('#fourth-fig', .5, {y:200, opacity: 0});
    tl2.from('#fifth-fig', .5, {y:200,opacity: 0});
    tl2.from('#sixth-fig', .5, {y:200, opacity: 0});
    
    const firstScene = new ScrollMagic.Scene({
      triggerElement: "#second-h1"
    })
      .setTween(tl)
            .addTo(controller);
    
    const secondScene = new ScrollMagic.Scene({
      triggerElement: "#first-img"
    })
      .setTween(tl2)
            .addTo(controller);
    @import url("https://fonts.googleapis.com/css?family=Arapey");
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: inherit;
    }
    
    html {
      box-sizing: border-box;
      font-size: 62.5%;
    }
    
    body {
      font-family: "Arapey";
      font-weight: 700;
      background: #dfe6e9;
    }
    
    .container {
      position: relative;
    }
    
    h1 {
      margin: 0 auto;
      width: 100rem;
      text-align: center;
      font-size: 6rem;
    }
    
    .section--1 {
      height: 100rem;
      background: #bdc3c7;
    }
    
    .section--2 {
      margin: 0 auto;
      width: 100rem;
    }
    
    .images {
      display: grid;
      padding: 0.5rem;
      margin: 2rem auto;
      width: 100%;
      grid-template-rows: repeat(auto-fill, 25rem);
      grid-template-columns: repeat(3, 1fr);
      grid-gap: 0.8rem;
      grid-auto-columns: 1fr;
      grid-auto-rows: 25rem;
    }
    .images--img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TimelineMax.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/ScrollMagic.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/plugins/animation.gsap.min.js"></script>
    
    
    <div class="container">
      <section class="section--1">
        <h1>Scroll down to see the animations</h1>
      </section>
      <section class="section--2">
        <h1 id="second-h1">
          hello there I love code and music
        </h1>
        <div class="images">
          <figure class="images--fig" id="first-fig"><img src="https://images.unsplash.com/photo-1485170536212-67180b105ff6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" alt="" class="images--img" id="first-img"></figure>
          <figure class="images--fig" id="second-fig"><img src="https://images.unsplash.com/photo-1518257678582-d5c9bb2e6ec9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=588&q=80" alt="" class="images--img"></figure>
          <figure class="images--fig" id="third-fig"><img src="https://images.unsplash.com/photo-1540821924489-7690c70c4eac?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=991&q=80" alt="" class="images--img"></figure>
          <figure class="images--fig" id="fourth-fig"><img src="https://images.unsplash.com/photo-1484755560615-a4c64e778a6c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=980&q=80" alt="" class="images--img" id="fourth-img"></figure>
          <figure class="images--fig" id="fifth-fig"><img src="https://images.unsplash.com/photo-1481207727306-1a9f151fca7d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" alt="" class="images--img"></figure>
          <figure class="images--fig" id="sixth-fig">
            <img src="https://images.unsplash.com/photo-1517852058149-07c7a2e65cc6?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80" alt="" class="images--img">
          </figure>
        </div>
      </section>
      <section class="section--1"></section>
    </div>
    Login or Signup to reply.
  6. Here is barebone structure similar to the example website using a tiny library @opuu/inview.

    The parallax effect and animation on scroll both can be done with this same library very easily.

    body {
      margin: 0;
      padding: 0;
    }
    
    #container {
      position: relative;
      width: 100%;
    }
    
    #background {
      background: url('https://picsum.photos/seed/picsum/700/500');
      background-size: cover;
      background-position: center;
      height: 150vh;
      width: 100%;
    }
    
    #foreground {
      background-color: blue;
      transition: margin-top 0.1s;
      height: 200vh;
      width: 70%;
      margin: 0 auto;
    }
    
    #effect {
      padding: 20px;
      width: 100%;
      background-color: brown;
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
    
    .aos {
      transform: translateY(500px);
      transition: all 0.5s;
    }
    
    .aos.active {
      transform: translateY(0);
      transition: all 0.5s;
    }
    
    #empty {
      height: 100vh;
      width: 100%;
      background-color: green;
    }
        <div id="container">
            <div id="background">
                Background with image
            </div>
            <div id="foreground">
                Content that overlays the background
            </div>
            <div id="effect">
                <img class="aos" loading="lazy" src="https://picsum.photos/seed/picsum/700/500" alt="">
                <img class="aos" loading="lazy" src="https://picsum.photos/seed/picsum/700/500" alt="">
            </div>
            <div id="effect">
                <img class="aos" loading="lazy" src="https://picsum.photos/seed/picsum/700/500" alt="">
                <img class="aos" loading="lazy" src="https://picsum.photos/seed/picsum/700/500" alt="">
            </div>
            <div id="empty">
    
            </div>
        </div>
        
            <script type="module">
            import InView from "https://unpkg.com/@opuu/[email protected]/dist/inview.js";
    
            let hero = new InView("#background");
    
            hero.on("enter", (event) => {
                document.querySelector("#foreground").style.marginTop = `-${100 - event.percentage}vh`;
            });
    
            let effect = new InView(".aos");
            let queue = 0;
            effect.on("enter", (event) => {
                if (queue == 0) {
                    event.target.style.transitionDelay = "0.2s";
                    event.target.classList.add("active");
                    queue = 1;
                } else {
                    event.target.classList.add("active");
                    queue = 0;
                }
            });
    
            // effect.on('exit', (event) => {
            //     event.target.classList.remove("active"); // you can also add remove animation
            // });
        </script>

    Note: I am the author of this library.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search