jQuery 左右滚动效果是一种常见的网页动画效果,用于在网页上实现元素的平滑滚动。以下是一个简单的示例代码,展示了如何使用 jQuery 实现左右滚动效果。
以下是一个简单的左右滚动效果的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 滚动效果</title>
<style>
#scrollContainer {
width: 300px;
overflow: hidden;
border: 1px solid #ccc;
}
#scrollContent {
display: flex;
animation: scroll 10s linear infinite;
}
.scrollItem {
min-width: 100px;
height: 100px;
background-color: #f0f0f0;
margin-right: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
}
@keyframes scroll {
0% { transform: translateX(0); }
100% { transform: translateX(-100%); }
}
</style>
</head>
<body>
<div id="scrollContainer">
<div id="scrollContent">
<div class="scrollItem">1</div>
<div class="scrollItem">2</div>
<div class="scrollItem">3</div>
<div class="scrollItem">4</div>
<div class="scrollItem">5</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// 可以在这里添加更多的 jQuery 交互逻辑
});
</script>
</body>
</html>
animation-duration
的值即可。通过以上代码和说明,你应该能够实现一个基本的左右滚动效果,并根据需要进行调整和优化。
云+社区沙龙online [新技术实践]
2022vivo开发者大会
云+社区技术沙龙[第28期]
云+社区沙龙online [新技术实践]
云+社区技术沙龙[第9期]
云+社区沙龙online [国产数据库]
DB TALK 技术分享会
云+社区开发者大会(北京站)
领取专属 10元无门槛券
手把手带您无忧上云