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

The easiest way to reset mysql root password

My mysql version is MYSQL V5.7.9, please use the ...

Use render function to encapsulate highly scalable components

need: In background management, there are often d...

Docker container monitoring and log management implementation process analysis

When the scale of Docker deployment becomes large...

Implementation of css transform page turning animation record

Page turning problem scenario B and C are on the ...

How to configure /var/log/messages in Ubuntu system log

1. Problem Description Today I need to check the ...

JavaScript function syntax explained

Table of contents 1. Ordinary functions 2. Arrow ...

How to install MySQL database on Ubuntu

Ubuntu is a free and open source desktop PC opera...

How to set PATH environment variable in Linux system (3 methods)

1. In Windows system, many software installations...

Nginx compiled nginx - add new module

1. View existing modules /usr/local/nginx/sbin/ng...

mysql 8.0.18 mgr installation and its switching function

1. System installation package yum -y install mak...

TypeScript enumeration basics and examples

Table of contents Preface What are enums in TypeS...

How to view files in Docker image

How to view files in a docker image 1. If it is a...