jQuery achieves large-screen scrolling playback effect

jQuery achieves large-screen scrolling playback effect

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:
  • Code for implementing a lyrics scrolling music player based on jQuery
  • jQuery implements the left and right interval scrolling effect of pictures (can be played automatically)
  • jQuery focus image switching (digital marking/manual/autoplay/horizontal scrolling)
  • jQuery realizes the message scrolling effect

<<:  Software Testing - MySQL (VI: Database Functions)

>>:  SpringBoot integrates Activiti7 implementation code

Recommend

Docker's flexible implementation of building a PHP environment

Use Docker to build a flexible online PHP environ...

Implementation example of JS native double-column shuttle selection box

Table of contents When to use Structural branches...

How to deploy Angular project using Docker

There are two ways to deploy Angular projects wit...

Example of using CSS3 to create Pikachu animated wallpaper

text OK, next it’s time to show the renderings. O...

A brief discussion on the perfect adaptation solution for Vue mobile terminal

Preface: Based on a recent medical mobile project...

UDP simple server client code example

I won’t go into details about the theory of UDP. ...

10 excellent Web UI libraries/frameworks

1. IT Mill Toolkit IT Mill Toolkit is an open sou...

6 Ways to Elegantly Handle Objects in JavaScript

Table of contents Preface 1. Object.freeze() 2. O...

Solution for Baidu site search not supporting https (tested)

Recently, https has been enabled on the mobile ph...

How to use http and WebSocket in CocosCreator

Table of contents 1. HttpGET 2. HTTP POST WebSock...

Try Docker+Nginx to deploy single page application method

From development to deployment, do it yourself Wh...

js canvas realizes slider verification

This article example shares the specific code of ...