jquery 增加表格(jquery实现表格无缝滚动)
类别:编程学习 浏览量:779
时间:2021-10-16 00:50:23 jquery 增加表格
jquery实现表格无缝滚动本文实例为大家分享了jquery实现表格无缝滚动的具体代码,供大家参考,具体内容如下
css部分我是用的弹性布局
*{ margin:0; padding:0; } ul,li{ list-style:none; } .tableBox{ width:500px; height:520px; background:#e8e8e8; margin:0 auto; overflow:hidden; } .slide-title{ height:2.5rem; line-height:2.5rem; display:flex; background:#223e80; color:#fff; text-align:center; } .slide-title span{ flex:1; } .slide-list li{ line-height:1.875rem; height:1.875rem; display:flex; } .slide-list li span{ flex:1; text-align:center; } .slide-list li.odd{ background:rgba(0,0,0,.3) }
结构部分
<li class="tableBox"> <li class="slide-title"> <span>title1</span> <span>title2</span> <span>title3</span> </li> <li class="slide-container"> <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="odd"><span>item3</span><span>item3</span><span>item3</span></li> <li class="even"><span>item4</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item5</span><span>item3</span><span>item3</span></li> <li class="even"><span>item6</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item7</span><span>item3</span><span>item3</span></li> <li class="even"><span>item8</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item9</span><span>item3</span><span>item3</span></li> <li class="even"><span>item10</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item11</span><span>item3</span><span>item3</span></li> <li class="even"><span>item12</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item13</span><span>item3</span><span>item3</span></li> <li class="even"><span>item14</span><span>item2</span><span>item2</span></li> <li class="odd"><span>item15</span><span>item3</span><span>item3</span></li> <li class="even"><span>item16</span><span>item2</span><span>item2</span></li> </ul> </li> </li>
最后就是关键部分,js部分
鼠标滑过时清除定时器的写法
$(function(){ //鼠标滑过时清除定时器 $(".slide-list").hover(function(){ clearInterval(scrollTimer); },function(){ scrollTimer=setInterval(function (){ autoScroll(".slide-list") },2000); }); function autoScroll(obj){ var tableUl = $(obj); var first = tableUl.find('li:first'); var height = first.height(); first.animate({ height:0 },500,function(){ first.css('height',height).appendTo(tableUl); }) } var scrollTimer = setInterval(function(){ autoScroll(".slide-list") },2000) })
2、鼠标滑过时不清除定时器
$(function(){ function autoScroll(obj){ var tableUl = $(obj); var first = tableUl.find('li:first'); var height = first.height(); first.animate({ height:0 },500,function(){ first.css('height',height).appendTo(tableUl); }) } setInterval(function(){ autoScroll(".slide-list") },2000) })
实现的效果:
接口轮询调用的时候踩了一个坑,如果换成接口调用,一定要记得加上有没有定时器的判断
if(timer != null) { clearInterval(timer); }
完整的代码如下
$(function(){ var allUrl = "http://localhost:8899/tv/alldata"; renderPage (); var timer = setInterval(function(){ renderPage () },5000); if(timer != null) { clearInterval(timer); } function renderPage () { console.log(111); $.ajax({ url:allUrl, async:true, success:function(result){ console.log(result); if(result.success === true){ console.log('数据',result.data); var niujuOneData = result.data.counts[0].tvmTvToolUsageCount; var niujuTwoData = result.data.counts[1].tvmTvToolUsageCount; var niujuThreeData = result.data.counts[2].tvmTvToolUsageCount; var niujuFourData = result.data.counts[3].tvmTvToolUsageCount; var recordTableData = result.data.history; var useTableOneData = result.data.usage.needCheckTools; var useTableTwoData = result.data.usage.expireCheckTools; var useTableThreeData = result.data.usage.usingTools; console.log('数据1',niujuOneData) renderNiuju ('#banshouOne','#otherOne','#totalOne',niujuOneData); renderNiuju ('#banshouTwo','#otherTwo','#totalTwo',niujuTwoData); renderNiuju ('#banshouThree','#otherThree','#totalThree',niujuThreeData); renderNiuju ('#banshouFour','#otherFour','#totalFour',niujuFourData); renderRecordTable ('#tvTableFour',recordTableData); renderUseStateTable ('#tvTableOne',useTableOneData); renderUseStateTable ('#tvTableTwo',useTableTwoData); renderUseStateTable ('#tvTableThree',useTableThreeData); } } }); }; /** * 扭矩间数据渲染函数 */ function renderNiuju (obj1,obj2,obj3,tableData) { var niujuWrenchString = '<li class="tq-niuju-title-item blue">'+tableData.torqueToolTotalCount+'</li>' + '<li class="tq-niuju-title-item purple">'+tableData.torqueToolUsingCount+'</li>' + '<li class="tq-niuju-title-item green">'+tableData.torqueToolAvailableCount+'</li>' + '<li class="tq-niuju-title-item red">'+tableData.torqueToolNeedCheckCount+'</li>' var orderToolString = '<li class="tq-niuju-title-item blue">'+tableData.otherToolTotalCount+'</li>' + '<li class="tq-niuju-title-item purple">'+tableData.otherToolUsingCount+'</li>' + '<li class="tq-niuju-title-item green">'+tableData.otherToolAvailableCount+'</li>' + '<li class="tq-niuju-title-item red">'+tableData.otherToolNeedCheckCount+'</li>' var toolTotalString = '<li class="tq-niuju-title-item blue">'+tableData.totalToolCount+'</li>' + '<li class="tq-niuju-title-item purple">'+tableData.totalToolUsingCount+'</li>' + '<li class="tq-niuju-title-item green">'+tableData.totalToolAvailableCount+'</li>' + '<li class="tq-niuju-title-item red">'+tableData.totalToolNeedCheckCount+'</li>' $(obj1).html(niujuWrenchString) $(obj2).html(orderToolString) $(obj3).html(toolTotalString) } /** *操作记录表格渲染函数 */ function renderRecordTable (obj,tableData){ var tableString = ''; $.each(tableData,function(index,value){ if(index % 2 == 0){ tableString += ' <li class="odd">'+ '<li class="tq-des">'+value.content+'</li>'+ '<li class="tq-time">'+value.createTime+'</li>'+ '</li>' }else{ tableString += ' <li class="even">'+ '<li class="tq-des">'+value.content+'</li>'+ '<li class="tq-time">'+value.createTime+'</li>'+ '</li>' } }); $(obj).empty(); $(obj).html(tableString); } function renderUseStateTable (obj,tableData){ var tableString = ''; $.each(tableData,function(index,value){ if(index % 2 == 0){ tableString += '<li class="odd">'+ '<span>'+value.totalPositionEncoding+'</span><span>'+value.toolCode+'</span>'+ '</li>' }else{ tableString += '<li class="even">'+ '<span>'+value.totalPositionEncoding+'</span><span>'+value.toolCode+'</span>'+ '</li>' } }) $(obj).html(tableString); } setInterval(function(){ autoScroll("#tvTableOne") autoScroll("#tvTableTwo") autoScroll("#tvTableThree") autoScroll("#tvTableFour") },2000) function autoScroll(obj){ var tableUl = $(obj); var first = tableUl.find('li:first'); var height = first.height(); first.animate({ height:0 },500,function(){ first.css('height',height).appendTo(tableUl); }) } });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
您可能感兴趣
- jquery中one()的用法
- jquery如何优化
- jQuery对象和DOM的相互转换
- jquery中append和appendto的区别
- jQuery给动态添加的元素绑定事件
- jquery插件写法
- JQuery中serialize与serializeArray
- jQuery 右侧浮动导航菜单
- Jquery中parent()和parents()
- jquery插件开发
- jQuery end()
- jquery实现在光标位置插入内容
- jQuery里$(this)和this的区别有哪些
- jquery中is()
- jQuery如何操作下拉框select
- Jquery中的offset()和position()的区别
- 他是梁山最早的头目,江湖人称 旱地忽律 ,宋江几乎将其遗忘(他是梁山最早的头目)
- 梁山创始人杜迁,为何不受宋江待见,只排名83位(梁山创始人杜迁)
- 法国面包(法国面包法棍)
- 微信(微信分身)
- 双十二(双十二和双十一哪个划算)
- 佛肚竹盆景的养护之道(佛肚竹盆景的养护之道)
热门推荐
- mysql查询killed状态的进程(MySQL kill指令使用指南)
- mysql日志功能介绍(mysql日志系统的简单使用教程)
- 如何学会python多线程(Python3多线程基础知识点)
- docker 限制cpu使用率(docker CPU限制的实现)
- 简单介绍HTTPS与HTTP的区别
- pyqt5实例讲解(PyQt5实现简易计算器)
- sqlserver备份整表数据的语句(SqlServer批量备份多个数据库且删除3天前的备份)
- sql server修改sa密码(sqlserver添加sa用户和密码的实现)
- 用python怎么找工作(利用python如何在前程无忧高效投递简历)
- windows 10中如何安装numpy(windows下numpy下载与安装图文教程)