Advertisement
  1. Web Design
  2. UX/UI
  3. UI Design

How to Give Your Logo the “Slip Scroll” Effect

Scroll to top

In today's tutorial we're going to use JavaScript to create a simple, flexible, parallax effect where a logo seemingly changes colors with the background it's on when the user scrolls.

Slip scroll effectSlip scroll effectSlip scroll effect
The Slip Scroll effect in action

We'll be creating a “default” element which holds true to its placement (position: fixed), and a bunch of “moveable” elements whose position is dependent on that “default” element. We’ll use JavaScript to make this happen every time the user scrolls.

Note: to cover all bases I've provided the explanation in video and written form. 

Watch the Video

Subscribe to Tuts+ Web Design on Youtube

Read the Tutorial

Base Markup

We'll start by creating a couple of containing elements. Let’s make one of their backgrounds dark and one light so we can have a contrasting image contained in them. Let’s also go ahead and make our first image the "default" image by giving it a class of default, whilst the other images will get the class of moveable.

1
<div class="container dark">
2
  <img src="img/acme-light.svg" class="default">
3
</div>
4
5
<div class="container light">
6
  <img src="img/acme-dark.svg" class="moveable">
7
</div>

Base Styles

Now let’s make sure our images don’t end up scrolling outside of their containers by setting overflow: hidden. We’ll also go ahead and say these containers have relative position, so the absolutely positioned elements will align to these containers instead of directly to the fixed element when we write our JavaScript. 

For the sake of scrollability, let’s give these containers a min-height of around 400px. And to hold our logos away from the edges, let's give them some padding of 1em.

1
.container {
2
  overflow: hidden;
3
  position: relative;
4
  min-height: 400px;
5
  padding: 1em;
6
}

Each container needs some contrasty color so:

1
.dark {
2
  background: #333;
3
}
4
5
.light {
6
  background: #fff;
7
}

And finally, as promised, let's set our default and moveable CSS so one is stuck with the page as the user scrolls, and the other is moving along with it without bumping into other elements:

1
.default {
2
  position: fixed;
3
}
4
5
.moveable {
6
  position: absolute;
7
}

That should take care of the markup and styling. If you view the page, you should see the default logo scrolling down and hiding behind the other containers, whilst all the moveable logos should appear as normal elements in the top-left of their respective containers.

Introducing JavaScript

Now for the fun part, making it work with JavaScript.

First we'll load jQuery and our custom script at the bottom of our index.html:

1
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
2
    <script src="js/slipScroll.js"></script>
3
  </body>
4
</html>

Create and open a file named js/slipScroll.js.

Within that file, the first thing we’ll do is create a function called setLogo and throw this function into a jQuery scroll event so that every time the user scrolls a pixel, this event fires. We'll also want to make sure we fire this event when the user first arrives at the page (before they scroll):

1
var setLogo = function() {
2
3
};
4
5
$(document).scroll(function() {
6
  setLogo();
7
});
8
9
setLogo();

Getting Things Working

Now for the magic. Let’s say that every single instance of .moveable on the page should change its CSS top position to however far the default image is from the top of the page, minus however far this .moveable element's container is from the top of the page.

1
var setLogo = function() {
2
3
  $('.moveable').each(function() {
4
    $(this).css('top',
5
      $('.default').offset().top -
6
      $(this).closest('.container').offset().top
7
    );
8
  });
9
10
};

Refresh your page, and voila! You’ve just created a pseudo-parallax scrolling effect from scratch in just a few lines of code.

Conclusion

I encourage you to tinker around with this solution. Try playing with the JavaScript function itself to see what kind of weird offsets you get if you add or remove a few pixels. Try using different elements (navigation anyone?) instead of just images for your scrollable content.

I hope you learned a lot and feel free to drop comments below if you have any questions.

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.