首页 前端知识 【jQuery】实现列表滚动

【jQuery】实现列表滚动

2024-02-19 09:02:44 前端知识 前端哥 292 290 我要收藏

利用jQuery实现列表滚动效果

文章目录

  • 一、展现效果
  • 二、实现代码
    • 1.html+css
    • 2.js代码


一、展现效果

在这里插入图片描述

二、实现代码

1.html+css

代码如下(示例):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
.wrapper {
width: 300px;
height: 356px;
border: 1px solid;
margin: 0 auto;
position: relative;
overflow: hidden;
}
ul {
width: 100%;
background-color: lightblue;
position: absolute;
}
li {
list-style: none;
height: 50px;
border-bottom: 1px dotted;
text-align: center;
line-height: 50px;
}
p {
position: absolute;
border: 1px solid red;
}
</style>
</head>
<body>
<button>开始</button>
<div class="wrapper">
<ul>
<li>张三</li>
<li>李四</li>
<li>王五</li>
<li>赵六</li>
<li>黄磊</li>
<li>玛丽</li>
<li>多啦</li>
<li>琪琪</li>
</ul>
</div>
</body>
</html>
复制

2.js代码

代码如下(示例):

<script src="js/jquery-3.6.0.js"></script>
<script>
$(function() {
play();
var id;
function play() {
id = setInterval(function() {
$("ul").animate({
"top": "-52px"
}, 1000, function() {
$(this).append($("li:first"));
$(this).css("top", "0")
});
}, 1500)
}
$(".wrapper").hover(
function() {
clearInterval(id)
},
function() {
play();
}
)
})
</script>
复制

转载请注明出处或者链接地址:https://www.qianduange.cn//article/2299.html
标签
评论
发布的文章

jquery初始化方法

2024-03-04 10:03:13

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!