Ajax Loader
×

CSS3-Marquee

Improved Version of Creating Advanced "Marquee" with CSS3 Animation with only one animation for all news items.

For n items, create (n - 1) delays for all elements except the first one with an ascending duration of (anim-time / n) seconds for each item. Then also repartition the first four keyframes to a percentage of (100 / n).

HTML
<div class="marquee">
1
<div class="marquee">
2
  <p>Brisante News #1</p>
3
  <p>Brisante News #2</p>
4
  <p>Brisante News #3</p>
5
  <p>Brisante News #4</p>
6
  <p>Brisante News #5</p>
7
</div>
8
 
 
CSS
html, body {
1
html, body {
2
  background: url('http://subtlepatterns.com/patterns/skewed_print.png');
3
}
4
 
5
/* container for news items */
6
.marquee {
7
  width:            500px;
8
  height:            50px;
9
  margin:            25px auto;
10
  overflow:         hidden;
11
  position:         relative;
12
  
13
  border:           1px solid #000;
14
  border-radius:    5px;
15
  background-color: #222;
16
  box-shadow:       inset 0px 2px 2px rgba(0, 0, 0, .5),
17
    0px 1px 0px rgba(250, 250, 250, .2);
18
  
19
  counter-reset:    marqueeindex;
20
}
21
/* paragraphs with news */
22
.marquee p {
23
  position:         absolute;
24
  width:            100%;
25
  height:           100%;
26
  margin:           0;
27
  color:            #fff;
28
  text-align:       center;
29
  font-family:      Tahoma, Arial, sans-serif;
30
  text-shadow:      1px 1px 0px #000000;
31
  filter:           dropshadow(color=#000000, offx=1, offy=1);
32
  
33
  line-height:      50px;       /* height of ontainer */
34
  transform: translateY(-100%); /* start above container */
35
}
36
 
37
/* prepend number for each paragraph */
38
.marquee p:before {
39
  counter-increment: marqueeindex;
40
  content: counter(marqueeindex) ": ";
41
}
42
 
43
 
44
/* use same animation for each paragraph */
45
.marquee p {
46
  animation: shownews 20s ease infinite;
47
}
48
 
49
/* ascending animation delay after first news item */
50
.marquee p:nth-child(2) { animation-delay:  4s; }
51
.marquee p:nth-child(3) { animation-delay:  8s; }
52
.marquee p:nth-child(4) { animation-delay: 12s; }
53
.marquee p:nth-child(5) { animation-delay: 16s; }
54
 
55
/* pause animation on hover */
56
.marquee:hover p {
57
  animation-play-state: paused;
58
}
59
 
60
/* animation for displaying one element */
61
@keyframes shownews {
62
  0%  {
63
    transform:translateY(-100%);
64
  }
65
  5% {
66
    transform:translateY(0);
67
  }
68
  15% {
69
    transform:translateY(0);
70
  }
71
  20% {
72
    transform:translateY(100%);
73
  }
74
  100%{
75
    transform:translateY(100%);
76
  }
77
}
78
 
 

CSS3-Marquee

CSSDeck G+