我想创建一个记分牌,列出最近的获奖者。当宣布新的获胜者时,我希望三个当前的获胜者向右滑动,新的获胜者从左边滑到适当的位置,最老的获胜者(最右边)滑出屏幕。
使用下面的代码,除了右侧之外,我一切正常。现在,它就消失了(我希望它优雅地滑出右侧)。
HTML
<div id="results-wrapper">
<div class="contest-results" id="recent-winners">Recent winners:</div>
<div class="contest-results" id="winner-wrapper">
<div class="winner">John</div>
<div class="winner">Katie</div>
<div class="winner">Peter</div>
</div>
</div>
CSS
#results-wrapper {
display:inline-block;
padding: 6px 3px 4px 3px;
font-size: 16px;
}
.contest-results {
float:left;
}
#recent-winners {
width: 120px;
text-align: left;
}
#winner-wrapper {
width: 444px;
height: 20px;
white-space: nowrap;
overflow: hidden;
}
.winner {
text-align: center;
width: 148px;
float:left;
position: relative;
display: inline;
}
JS
$("#winner-wrapper").on("click", ".winner", function() {
$('.winner:first').before('<div style="display: none;" class="winner">justin</div>');
$('.winner').css({"display" : "inline", "left" : "-148px"});
$('.winner').animate({"left" : "0px"}, {duration : 600, easing : "swing"});
$('.winner:last').remove();
});