目的是一個具有固定的高度和寬度具有容器DIV和具有內的HTML內容垂直連續DIV自動滾動顯示。
問題 基本上我已經創建下面使用jQuery滾動(移動)子DIV垂直向上的代碼,直到它的邊界框父其中動畫隨後完成其觸發的事件處理程序,其重置的位置外孩子DIV並再次啓動該過程。
這工作正常,所以內容向上滾動留下一個空白區域,然後再次從底部開始滾動。
我遇到的問題是,對於內容的要求就好像它不斷重複出現,請參見下圖以更好地解釋這一點,有沒有辦法做到這一點? (我不希望使用第三方插件或庫比jQuery的除外):
alt text http://www.cameroncooke.com/playground/scrolling-example.gif
我有什麼到目前爲止
的HTML:
<div id="scrollingContainer">
<div class="scroller">
<h1>This is a title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at orci mi, id gravida tellus. Integer malesuada ante sit amet enim pulvinar congue. Donec pulvinar dolor et arcu posuere feugiat id et felis.</p>
<p>More content....</p>
</div>
</div>
該CSS:
#scrollingContainer{
height: 300px;
width: 300px;
overflow: hidden;
}
#scrollingContainer DIV.scroller{
position: relative;
}
中的JavaScript:
/**
* Scrolls the content DIV
*/
function scroll() {
if($('DIV.scroller').height() > $('#scrollingContainer').height()) {
var t = $('DIV.scroller').position().top + $('DIV.scroller').height();
/* Animate */
$('DIV.scroller').animate(
{
top: '-=' + t + 'px'
}
, 4000, 'linear', animationComplete);
}
}
function animationComplete() {
$(this).css('top', $('#scrollingContainer').height());
scroll();
}