3

I am trying to achieve a color effect that looks like a color sliding across a viewport area that cannot have scroll bars. So it looks like a linear transition from one color to another from either the left or the right. For illustration (of color 1 being replaced by color 2 from the right):

+----------+ +----------+ +----------+
|1111111112| |1111111222| |1111122222|
|1111111112| |1111111222| |1111122222|
|1111111112| |1111111222| |1111122222|
|1111111112| |1111111222| |1111122222|
|1111111112| |1111111222| |1111122222|
+----------+ +----------+ +----------+

In order to attempt this before, I had a div that was larger than the viewport (500%) and it had 5 child divs (each 20% width). I was then using jquery to scroll the larger viewport and the resulting scroll gave the illusion of my wanted color transition. However, I am trying to do a similar process with variable color (the user can enter the color and then choose whether or not it enters from the left or right). So a static-scrolling setup will no longer work. I have tried something below:


+-----+-----+-----+
|Left | View|Right|
|     |     |     |
| Area|Area |     |
|     |     |Area |
+-----+-----+-----+

The View area is 100% of the viewport, the left and right areas are not present. When the user selects a color and a side from which to transition from, I then use jquery to insert a new div into the container with that requested background color. I give it the css values of either {left: 100%}, putting it in the right area) or {left: -100%}, putting it in the left area. However, because my view area takes up 100% of the width of my viewport, css puts whatever I insert below my viewing area. I have attempted a few combinations of css in order to fix this, but none have worked.

#area-container {
overflow: hidden;
width: 100%;
height: 100%;
float: left;
position: relative;
}

.color-areas{
width: 100%;
height: 100%;
position: relative;
float: left;
display: inline-block;
}

Anybody willing to suggest an alternative means for this animation or help me with this css issue?

EDIT: Jsfiddle: https://jsfiddle.net/jm8j8ghh/6/

EDIT2: SOLVED IT. All I had to do was make the container have a relative position and the areas inside of it an absolute position. As discussed in an answer here: Prevent floated divs from wrapping to new line

Final jsfiddle: https://jsfiddle.net/jm8j8ghh/7/

Community
  • 1
  • 1
user1519665
  • 511
  • 5
  • 16
  • Do you have a more complete code example, including JavaScript? If so, could you put that in a runnable snippet in the question? – Drew Gaynor Sep 29 '15 at 20:06
  • what about css color gradients? http://www.w3schools.com/css/css3_gradients.asp – toskv Sep 29 '15 at 20:07
  • Let me try to put together a jsfiddle @toskv, No, sadly, I'm not looking for a gradient effect, I'm looking for a single-solid-color-bar to advance across the page and "overlay" the current background color. – user1519665 Sep 29 '15 at 20:08
  • @user1519665 is this something that fits your bill (it's in angular but the css ought to be the same)? You can set the overflow to hidden and use jquery to scroll as you wish. http://plnkr.co/edit/zdxdPE8xDswG1lAwnavi?p=preview – toskv Sep 29 '15 at 20:35
  • just as a note you should probably add browser specific flex attributes, I used chrome. :) – toskv Sep 29 '15 at 20:37
  • @toskv While in retrospect, Angular probably would have been better to use, I also need the old colors to be "deleted" as I scroll away. So "adding panes" wouldn't work unless I could delete panes. And having tried that style before, deleting panes and resizing the viewport's contents messes with the scrolling and position of the contents. – user1519665 Sep 29 '15 at 20:49
  • well.. angular shouldn't matter in this case, what matters is the way the items are styled. Using flex-box you can just set the wrapping to nowrap and it should never move your content below. I tried it with your jsfiddle but it seems to break the animations. :( – toskv Sep 29 '15 at 20:51

1 Answers1

1

Feel really silly it was this simple: changed the internal container positions to absolute and it worked like a charm!

user1519665
  • 511
  • 5
  • 16