r/csshelp • • May 09 '14

Resolved Animated header CSS3 question

I am working on /r/bestofsoundcloud and currently (with /u/gavin19's help) the .pagename a is centered in the header and replaced with an image, is it possible to have that image scroll into place from the far left side of the screen (and be z-indexed behind the snoo image) upon initial page load?

Any help is appreciated as always.

9 Upvotes

7 comments sorted by

5

u/preggit May 09 '14 edited May 09 '14

This took me awhile but I got it working! Here you go:

.pagename a
{
  background: url(%%your_image_here%%);
  background-repeat: no-repeat;
  background-position: 50% 0;
  width:100%;
  height:125px;
  position:absolute;
  animation:headerslide 16s;
  animation-direction:linear;
  -webkit-animation:headerslide 16s;
  -webkit-animation-direction:linear;
  text-indent:-9999px;
  z-index:100;
}

@keyframes headerslide
{
   from { 
     background-position: -50% 0; 
   }
	
   to { 
     background-position: 50% 0;
   }   
}

@-webkit-keyframes headerslide
{
   from { 
     background-position: -50% 0; 
   }
	
   to { 
     background-position: 50% 0;
   }
}

3

u/[deleted] May 09 '14

Thank you so much! I credited you in the stylesheet, this is awesome.

1

u/preggit May 09 '14

No problem, glad I could help! If you want to speed up or slow down the animation you can change the 16s to whatever you'd like. Also if you want to change the positioning just modify the 50% - that seemed about where it was at on your current stylesheet which is why I chose it.

2

u/[deleted] May 10 '14

Sorry to bug you again, but I took part of your code and combined it with code from a css3 generator to make the image on /r/ObscureMedia grow into place, I targeted only the .hot-page with the animation and have a static type image on the other pages so it wont animate when you check new or go to comment, the issue is the x position is off a little, I can't figure out how to move them around so they match perfectly on page change.

It's no big deal if you are busy, it works fine as is, it's just my OCD.

1

u/preggit May 10 '14

Anywhere you see background-position that is referring to:

x% y% The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. . Default value is: 0% 0%

So try adjusting those percentages to get it to where you want it.

1

u/[deleted] May 10 '14 edited May 10 '14

ahh, thanks, i think i can trial and error it into place.

Edit: I worked around the issue by copying the animation code from
.hot-page .pagename a
and using it as a static image for
.pagename a
by changing the animation duration to 1ms, this way they end up in the exact same position.

2

u/preggit May 09 '14

Oh yeah, if you want this to work with older versions of firefox you need to add -moz- entries everywhere you see the -webkit- (so -moz-animation:headerslide 16s; and a @-moz-keyframes headerslide definition)