2015-06-05 11 views
5

Ich versuche, eine automatische Scrolling-Liste mit CSS-Animation zu erstellen.So erstellen Sie eine automatische Scrolling-Liste

Was ich jetzt habe:

.players { 
 
    -webkit-transition: opacity 0.5s ease-out; 
 
    -webkit-animation: autoScrolling 5s linear infinite; 
 
    height: 20em; 
 
} 
 
.players .list-group-item { 
 
    height: 5em; 
 
} 
 
@-webkit-keyframes autoScrolling { 
 
    from { 
 
    margin-top: 0; 
 
    } 
 
    to { 
 
    margin-top: -20em; 
 
    } 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="row"> 
 
    <div class="col-md-6"> 
 
    <ul class="list-group players"> 
 
     <li class="list-group-item">Player 1</li> 
 
     <li class="list-group-item">Player 2</li> 
 
     <li class="list-group-item">Player 3</li> 
 
     <li class="list-group-item">Player 4</li> 
 
    </ul> 
 
    </div> 
 
</div>

Frage ist, ist es möglich, Spieler 1 zeigt unter Wiedergabe 4 zu machen, während es von der Spitze verschwindet? Wie ein End-End-Kreis.

JavaScript-Lösung ist eine Option.

+0

Könntest du die Pos von player 4 dom Element überprüfen und wenn es an einer bestimmten oberen Position ist, dupliziere das player 1 dom Element und füge es unter Player 4 an? –

+0

Danke, ich versuche zu vermeiden, dass bcz die Liste von eckigen generiert wurde. Ändern der Dom könnte zu etwas führen, was ich nicht will .. – lastr2d2

Antwort

3

Versuchen Sie, diese Demo.

window.players = function($elem) { 
    var top = parseInt($elem.css("top")); 
    var temp = -1 * $('.players > li').height(); 
    if(top < temp) { 
     top = $('.players').height() 
     $elem.css("top", top); 
    } 
    $elem.animate({ top: (parseInt(top)-60) }, 600, function() { 
     window.players($(this)) 
    }); 
} 
$(document).ready(function() { 
    var i = 0; 
    $(".players > li").each(function() { 
      $(this).css("top", i); 
      i += 60; 
      window.players($(this)); 
    }); 
}); 
+0

das ist ziemlich cool .. danke – lastr2d2

+0

Sie sind willkommen. – stanze

0

Sie können es hilft so etwas wie dieses

$(".list-group-item:first").clone().appendTo($(".list-group")).hide().show('slow'); 
$(".list-group-item:first").hide('slow'); 
setTimeout(function(){ 
    $(".list-group-item:first").remove(); 
},500); 

Hoffnung versuchen!

Verwandte Themen