目的是一个具有固定的高度和宽度具有容器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();
}