This article example shares the specific code of jQuery to achieve the scrolling effect of table row data for your reference. The specific content is as follows HTML code: <div class="box"> <div class="box-header"> <div class="col">Test 1</div> <div class="col">Test 2</div> <div class="col">Test 3</div> <div class="col">Test 4</div> </div> <div id="font-scroll"> <div class="box-body"> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> <div class="row"> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> <div class="col">Test text</div> </div> </div> </div> </div> CSS style code: .box { width: 400px; text-align: center; font-size: 14px; border: 1px solid rgba(0, 0, 0, .3); } .box .box-header { display: flex; justify-content: space-evenly; } .box-body .row { display: flex; justify-content: space-evenly; } .box-header, .box-body .row { border-bottom: 1px dashed #404040; } .box .col { padding: 10px 0 10px 0; } .box .col:nth-child(1) { width: 80px; } .box .col:nth-child(2) { width: 60px; } .box .col:nth-child(3) { width: 80px; } .box .col:nth-child(4) { width: 60px; } /* Content scrolling */ #font-scroll { /* Content scrolling visible height*/ height: 199px; overflow: hidden; } JS code: (function ($) { $.fn.FontScroll = function (options) { let d = { time: 1000 } $.extend(d, options); // The div parent box that needs to be scrolled let box = this[0] // scroll interval let _time = d.time // This method is only suitable for the case where the height of each row of data is the same // // The height of each scroll (usually the height of a data line) // let _contentChildHeight = box.children[0].children[0].offsetHeight // // The total scroll height, that is, the total height of the content (the total height of all data) // let _contentTotalHeight = _contentChildHeight * box.children[0].children.length // This method is suitable for all cases, including the case where the height of each row of data is different // Get all row elements let all_row_el = box.children[0].children // Total row height let _contentTotalHeight = 0 // The superposition height of each row of data and the height of all previous rows let _contentChildHeight = [] for (let i in all_row_el) { if ((new RegExp("^\\d+$")).test(i)) { _itemHeight = all_row_el[i].offsetHeight _contentTotalHeight += _itemHeight i == 0 ? _contentChildHeight.push(_itemHeight) : _contentChildHeight.push(_contentChildHeight[i - 1] + _itemHeight) } } // The div subbox that needs to be scrolled let child1 = this.children('.box-body') // Clone the scrolling div child box // Clone method 1 // let child1 = this.children('.box-body')[0] // let child2 = this.children('.box-body')[1] // child2.innerHTML = child1.innerHTML // Clone method 2 if ((box.offsetHeight + 5) < _contentTotalHeight) { // If the data does not reach a certain height, the scrolling effect will not be performed child1.clone().insertAfter(child1) /*Start the timer*/ let timer = setInterval(autoScrollLine, 30) /*Single line scroll up effect*/ function autoScrollLine() { /* Determine whether the scrolling content has been scrolled, if it has been scrolled, reset the scroll value to 0 Otherwise, scroll up 1px every 30 milliseconds*/ if (box.scrollTop >= _contentTotalHeight) { box.scrollTop = 0; } else { box.scrollTop++; } /*Stop the timer when the scrolling distance is exactly the height of a data line. Restart the timer after _time to achieve the data scrolling effect*/ if (_contentChildHeight.indexOf(box.scrollTop) >= 0) { clearInterval(timer) setTimeout(() => { timer = setInterval(autoScrollLine, 30) }, _time) } } } } })(jQuery); Directions: $('#font-scroll').FontScroll({ time: 1000 }); Effect picture: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Summary of Linux ps and pstree command knowledge points
>>: 4 ways to modify MySQL root password (summary)
A web server can build multiple web sites with in...
HTML is the abbreviation of Hypertext Markup Langu...
I will be learning MySQL next semester. I didn...
introduction The company's recent Vue front-e...
VC6.0 is indeed too old VC6.0 is a development to...
Table of contents Preface Is the interviewer aski...
TranslateThis URL: http://translateth.is Google T...
Preface Nginx is a lightweight HTTP server that u...
1. According to the online tutorial, the installa...
Correct answer Using useRouter : // router path: ...
Original article, please indicate the author and ...
1. What is Docker Secret 1. Scenario display We k...
Cocos Creator version: 2.3.4 Demo download: https...
Recently, due to the increase in buttons in the b...
Problem description: The Linux system's netwo...