This article shares the specific code of jQuery to achieve the large-screen scrolling effect for your reference. The specific content is as follows Scenario requirements: On the big screen, the message will be played in real time, scrolling back and forth. Code: <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Checkbox custom style</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <style> * { margin: 0; padding: 0; } .contScend { width: 400px; height: 200px; background: #000000; margin: 20px auto; overflow: hidden; } .contScend ul { list-style: none; width: 100%; height: 100%; color:red; font-size: 13px; } .contScend ul li { width: 100%; height: 40px; box-sizing: border-box; line-height: 40px; text-align: center; } </style> </head> <body> <!-- Middle part --> <div class="contScend"> </div> </body> <script type="text/javascript"> $.ajax({ url: "test.json", type: 'GET', dataType: 'json', success: function(data) { var html = ""; html += '<ul>'; $.each(data, function(i, item) { // html += '<li>' + item.name + ':' + item.numb + '人' + '</li>'; }); html += '</ul>'; $(".contScend").html(html); scroll(); } }); function scroll() { //Get the current <ul> var $uList = $(".contScend ul"); var timer = null; //Touch to clear the timer $uList.hover(function() { clearInterval(timer); }, function() { //Leave to start the timer timer = setInterval(function() { scrollList($uList); }, 1000); }).trigger("mouseleave"); //Automatically trigger touch events //Scroll animation function scrollList(obj) { //Get the current <li> height var scrollHeight = $("ul li:first").height(); //Scroll out the height of a <li>$uList.stop().animate({ marginTop: -scrollHeight }, 600, function() { //After the animation ends, set the current <ul>marginTop to the initial value 0, and then splice the first <li> to the end. $uList.css({ marginTop: 0 }).find("li:first").appendTo($uList); }); } } </script> </html> test.json [{ "name": "Experience Zone Statistics", "numb": 0 }, { "name": "test909", "numb": 0 }, { "name": "test910", "numb": 0 }, { "name": "111", "numb": 0 }, { "name": "test", "numb": 0 }, { "name": "test11111", "numb": 0 }, { "name": "Memory Area Statistics", "numb": 0 }] The effect is as follows 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:
|
<<: Software Testing - MySQL (VI: Database Functions)
>>: SpringBoot integrates Activiti7 implementation code
Use Docker to build a flexible online PHP environ...
Table of contents When to use Structural branches...
There are two ways to deploy Angular projects wit...
GTID-based replication Introduction GTID-based re...
text OK, next it’s time to show the renderings. O...
Preface: Based on a recent medical mobile project...
I won’t go into details about the theory of UDP. ...
1. IT Mill Toolkit IT Mill Toolkit is an open sou...
Table of contents Preface 1. Object.freeze() 2. O...
Recently, https has been enabled on the mobile ph...
Code implementation: Copy code The code is as fol...
background Two network cards are configured for t...
Table of contents 1. HttpGET 2. HTTP POST WebSock...
From development to deployment, do it yourself Wh...
This article example shares the specific code of ...