-1

我制作了自己的实时 youtube 订阅者计数器,但刷新时间太长,当我更改刷新时间时,它不会发生。有人可以告诉我我做错了什么吗?

<html>
<head>
    <link rel="stylesheet" href="odometer-theme-default.css"/>
    <script src="odometer.js"></script>
    <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
    <style>
        .odometer {
        font-size:100px;
        }
        #ytName {
        font-size: 52px;
        font-family:Arial;
        }
    </style>
</head>
<script type="text/javascript">
 $(document).ready( function() {

     var chanName = "";

     loadChannel("UCPKqr9qSEXi6r03B18wRj6g");

     function loadChannel(name) {

        chanName = name;
        var url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id='+name+'&key=AIzaSyBPIHea9sWYMSxe8W-tIn7OUvIw-dagDDI';
        $.getJSON(url, function(data) {
            $("#odometer").html(data.items[0].statistics.subscriberCount);
        });

        var url1 = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&id='+chanName+'&key=AIzaSyBPIHea9sWYMSxe8W-tIn7OUvIw-dagDDI';
        $.getJSON(url1, function(data) {
            $('#ytName').html(data.items[0].snippet.title);
            $('#ytLink').html('<a href="http://youtube.com/' + data.items[0].snippet.customUrl + '\">Link</a>');
        });
    }

    setInterval( function() {

        var url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id='+chanName+'&key=AIzaSyBPIHea9sWYMSxe8W-tIn7OUvIw-dagDDI';
        $.getJSON(url, function(data) {
            $("#odometer").html(data.items[0].statistics.subscriberCount);
        }, 1000);

    });
});
</script>
<body background = "bg.jpg">
    <center>
        <div id="ytName"></div>
        <div id="ytLink"></div>
        <div id="odometer" class="odometer"></div>
    </center>
</body>

也许javascript应该以不同的方式编写?

4

1 回答 1

0

如果您以毫秒为单位写入新时间,则响应有点

setInterval( function() {

   // update code is here
}, 1000)
于 2018-11-25T20:26:05.607 回答