0
votes

I'm trying to recreate an effect like this: https://www.brontidebg.com/product The main image at the top of the screen (to the left) has a really smooth animation out into the screen (same with the image at the bottom). When you scroll to either image, they animate out in the same manner.

Here is what I've come up with:

HTML

<div class="top">
  <h1>scroll down<h1>
</div>

<div class="container">
  <div class="block image-block slideright">
    <figure>
      <img src="https://i.guim.co.uk/img/media/11d4c182d094199e26ddb36febe67123a9bbc93a/34_246_2966_4275/master/2966.jpg?w=700&q=55&auto=format&usm=12&fit=max&s=4a5b5fe1d34627003607df532913292d">
    </figure>
  </div>

  <div class="block text-block">
    <h2> Some text </h2>
  </div>
</div>

CSS

.top{
  height:100vh;
}
h1{
  text-align: center;
}

.block{
  display: inline-block;
  height: 100vh;
}

.image-block{

}

figure{
  position: relative;
        overflow: hidden;
        height: 100vh;
        width: 34vw;
  text-align: center;
  margin: 0;
}

image{
  height: 100vh;
  width: 34vw;
  position: relative;
  object-fit: cover;
}

.slideright{
    transform: translateX(-34vw);
    transition: all .8s ease-out;
}
.slideright.slideinright{
    transform: translateX(0);
}

JS

 $(window).scroll(function() {

    var winTop = $(window).scrollTop();

    $(".slideright").each(function(){
      var pos = $(this).offset().top;
      if (pos < winTop + 600) {
        $(this).addClass("slideinright");
      }
    });

    $(".slideleft").each(function(){
      var pos = $(this).offset().top;
      if (pos < winTop + 600) {
        $(this).addClass("slideinleft");
      }
    });

  });

Codepen (view in fullscreen since I'm using vh): https://codepen.io/Caj/pen/GdZwYP

As you can see, the image slides out as you scroll towards it, but it's not a smooth, professional looking animation like the example link. I'm also hoping to have the image slide out if you were to scroll up to the top and then back down (have the function run repeatedly, not just the first time you scroll to within view). Thanks in advance!

2

2 Answers

0
votes

Try this:

https://codepen.io/anon/pen/ZoWVxr

$(".slideright").each(function(){
      var pos = $(this).offset().top;
      if (winTop + 600 > pos) {
        $(this).addClass("slideinright");
      }
      if(winTop === 0) {
        $(this).removeClass('slideinright')
      }
    });

Added opacity, changed the speed and added the reset when the scroll is at the top. I changed your logic a bit so that it doesn't start the animation immediately, it only starts right when the image is in view. You can change the winTop + 600 to control when it starts. Add more to make it start earlier, less to make it start later. winTop + 200 would start the animation further down the scroll.

0
votes

You are almost there, but what gives that subtle touch of professionality to the animation is the choice of the ease function. I would try with a softer transition like this one:

transition: all 2s cubic-bezier(0.23, 1, 0.32, 1) 400ms;