jQuery无缝循环向上滚动是一种网页效果,通过JavaScript和CSS实现内容在页面上向上滚动的效果,且滚动过程中不会出现明显的停顿或重复现象。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Seamless Scroll Up</title>
<style>
#scroll-container {
width: 300px;
height: 200px;
overflow: hidden;
border: 1px solid #ccc;
}
#scroll-content {
position: relative;
height: auto;
}
.scroll-item {
height: 50px;
line-height: 50px;
border-bottom: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="scroll-container">
<div id="scroll-content">
<div class="scroll-item">Item 1</div>
<div class="scroll-item">Item 2</div>
<div class="scroll-item">Item 3</div>
<div class="scroll-item">Item 4</div>
<div class="scroll-item">Item 5</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
function scrollUp() {
var container = $('#scroll-container');
var content = $('#scroll-content');
var itemHeight = $('.scroll-item').height();
var scrollSpeed = 1000; // 滚动速度,单位毫秒
content.animate({ top: -itemHeight }, scrollSpeed, function() {
content.css('top', container.height());
scrollUp();
});
}
setInterval(scrollUp, 3000); // 每3秒滚动一次
});
</script>
</body>
</html>
通过以上方法,可以实现一个流畅且无缝的向上滚动效果,提升用户体验。
领取专属 10元无门槛券
手把手带您无忧上云