Home > Article > Web Front-end > Introducing a jquery special effect - seamless upward scrolling list
Effect presentation
The entire list moves up the height of an item at the set time interval
html structure:
<div class="slide-title"> <span>title1</span> <span>title2</span> <span>title3</span> </div> <div class="slide-container"><!--css设置时,注意高度是显示多少个item,如:item的高度是30px,显示3个,高度则是 3*30 = 90px --> <ul class="slide-list js-slide-list"> <li class="odd"><span>item1</span><span>item1</span><span>item1</span></li> <li class="even"><span>item2</span><span>item2</span><span>item2</span></li> <li class="even"><span>item2</span><span>item2</span><span>item2</span></li> </ul> </div>
Implementation idea:
Get js-slide -The height of the first li element under the list, its height or marginTop will be animated changed from present to nonexistent, the code is as follows:
var doscroll = function(){ var $parent = $('.js-slide-list'); var $first = $parent.find('li:first'); var height = $first.height(); $first.animate({ height: 0 //或者改成: marginTop: -height + 'px' }, 500, function() {// 动画结束后,把它插到最后,形成无缝 $first.css('height', height).appendTo($parent); // $first.css('marginTop', 0).appendTo($parent); });};setInterval(function(){doscroll()}, 2000); Demo1Demo2
The above is the detailed content of Introducing a jquery special effect - seamless upward scrolling list. For more information, please follow other related articles on the PHP Chinese website!