フェードインでニュースティッカーを表示させ、5秒後にニュースのテキストが左に流れていきます。全てテキストが流れた後に、次のテキストがフェードインで表示されます。

htmlのコードは下記の記事と同様です。
CSSのコードも上記の記事と同様ですが、1点だけ変更があります。
画像上に乗せている透過の背景色のdivタグ、#news_tickerにoverflow: hiddenを設定します。ニュースのテキストが左に流れていくと、透過の背景色のdivタグからはみ出した部分は非表示になります。
.fade_contents {
position: relative;
max-width: 600px;
margin: 0 auto;
}
#news_ticker {
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
background: rgba(255, 255, 255, 0.8);
font-size: 14px;
line-height: 50px;
overflow: hidden;
}
.news_ticker_list_item {
position: absolute;
max-width: 100%;
padding: 0 20px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
opacity: 0;
transition-duration: 1s;
transition-property: opacity;
transition-timing-function: ease;
z-index: -1;
}
.news_ticker_list_item.is-active {
opacity: 1;
z-index: 1;
}
.news_ticker_list_item time {
margin-right: 16px;
color: #6b9ed3;
}
.news_ticker_list_item a {
color: #000;
}
.news_ticker_list_item a:hover {
color: #6b9ed3;
}
@media screen and (max-width: 600px) {
#news_ticker {
height: 80px;
line-height: 1.3;
}
.news_ticker_list_item time {
display: block;
margin: 15px 0 8px;
}
}
最後にjQueryのコードです。
まずニュースのliタグの最初の1件目にクラス名is-activeを付与します。次にCSSでpositionをleft: 0にセットし、5秒後にニュースのliタグの長さプラス余白の20px分だけ左に移動します。この時の移動時間はニュースのliタグの長さ×15ミリ秒を設定します。左への移動完了後、ニュースのliタグの2件目にクラス名is-activeを付与し、endで1つ前の要素である1件目のニュースのliタグに戻ります。そして1件目のニュースのliタグからクラス名is-activeを削除し、appendToでニュースのliタグの一番最後に移動します。最後にtickerTxt関数を呼び出すことで処理を繰り返します。
$(function() {
function tickerTxt() {
if ($("#news_ticker").length) {
var a = $("#news_ticker_list");
var r = $(".news_ticker_list_item:first-child", a);
var width = r.width();
var speed = width * 15;
r.addClass("is-active");
$(".is-active", a).css({ left:0 }).delay(5000).animate({ left:-width - 20 }, speed, "linear", function() {
$(".is-active", a).next().addClass("is-active").end().removeClass("is-active").appendTo(a);
tickerTxt();
});
}
}
tickerTxt();
});