Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a fade effect in a horizontal scrolling div

Tags:

html

css

sass

I'm creating a horizontally scrolling div of music albums and want to have a fade on the right hand side of the div to help convey that the list scrolls horizontally.

I've almost cracked it, but can't quite understand why I can't get it exactly the way I want.

Here is a codepen of what I have so far... The fade (red for the sake of the example) works perfectly if the position is set to absolute but fails when set to fixed - which is what I need.

CodePen link

like image 893
Sean Avatar asked Nov 20 '17 21:11

Sean


People also ask

What handles perfectly creates horizontal linear fade?

For a linear fade, drag perfectly horizontally. For a logarithmic fade, drag up or down. For a cosine (S-curve) fade, hold down Ctrl (Windows) or Command (Mac OS).

What is horizontal scrolling?

Horizontal scrolling is a one-page navigation method designers can use. In this method, users can use different functionalities on a page to scroll right or left, to see more information within the container or window. Users scroll horizontally by clicking on a scroll bar and dragging it with their mouse or finger.


1 Answers

Attach the fade to the .artist__media not to .content. Like this:

.artist__media {
  margin-top: 50px;
  position: relative;

  &:after {
      content: "";
      position: absolute;
      z-index: 1;
      top: 0;
      right: 0;
      bottom: 15px;
      pointer-events: none;
      background-image: linear-gradient(to right, rgba(255,255,255,0), red 85%);
      width: 15%;
    }

  .content {
    white-space: nowrap;
    overflow-x: scroll;
    overflow-y: hidden;
    position: relative;
  }
}

See the fiddle. Is that what you wanted?

like image 169
zork media Avatar answered Sep 22 '22 16:09

zork media