在<td>标签中实现动态字幕横向滚动

10 篇文章 0 订阅
1 篇文章 0 订阅

1、首先看下效果

20190329111014925.png

20190329110934484.png

20190329111046677.png

2、主要是在表格第二列【important】以及【2019-2-21】上加了长度判断。如果长度超过限制范围,就执行横向滚动

3、代码如下:

css:

<style>
        .up {
            color: black;
            display: block;
            width: 96%;
            height: 20px;
            margin: 0 auto;
            position: relative;
            overflow: hidden;
        }
        .down {
            color: gray;
            display: block;
            width: 96%;
            height: 20px;
            margin: 0 auto;
            position: relative;
            overflow: hidden;
        }
        .up_text {
            position: absolute;
            top: 0;
            left: 100%;
            line-height: 20px;
            display: block;
            word-break: keep-all;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .down_text {
            position: absolute;
            top: 0;
            left: 100%;
            line-height: 20px;
            display: block;
            word-break: keep-all;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

    </style>

js[注:页面中如果没有引用jquery.js就单独再引用下]:

<script type="text/javascript">
    (function(){var timer = setTimeout(this.upCycle, 1000);}());
    function upCycle() {
        var upScrollWidth = $('.up').width();
        var upTextWidth = $('.up_text').width();
        var i = upScrollWidth;
        setInterval(function() {
            i--;
            if(i < -upTextWidth ) {
                i = upScrollWidth;
            }
            $('.up_text').animate({'left': i+'px'}, 20);
        }, 20);

        var downScrollWidth = $('.down').width();
        var downTextWidth = $('.down_text').width();
        var j = downScrollWidth;
        setInterval(function() {
            j--;
            if(j < -downTextWidth ) {
                j = downScrollWidth;
            }
            $('.down_text').animate({'left': i+'px'}, 20);
        }, 20);
    }
</script>

逻辑:

if(record.position.length > 7){
                            content += "<td class='text-center'>" + " <span class='up'>" + " <span class='up_text'>" + record.object + "</span></span>"  + " <span class='down'>" + " <span class='down_text'>" + record.position + "</span></span>" + "</td>";
                        }else{
                            content += "<td class='text-center'>" + " <span class='up'>" + " <span class='up_text'>" + record.object + "</span></span>"  + " <span class='color-gray'>" + record.position + "</span>" + "</td>";
                        }

觉得辛苦就扫一扫: 

 20190329111927164.png

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
<td>2023058</td> <td>10 17 22 26 30 33 + 11</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td>×</td> <td >0</td> </tr> <tr class="new"> <td>2023059</td> <td></td> <td>24</td> <td>10</td> <td>26</td> <td>31</td> <td>12</td> <td>33</td> <td>24</td> <td>08</td> <td>31</td> <td>24</td> <td></td> </tr> <tr> <td colspan="2">正确次数</td> <td>4</td> <td>3</td> <td>7</td> <td>2</td> <td>9</td> <td>3</td> <td>4</td> <td>5</td> <td>3</td> <td>6</td> <td></td> </tr> <tr> <td colspan="2">错误次数</td> <td>16</td> <td>17</td> <td>13</td> <td>18</td> <td>11</td> <td>17</td> <td>16</td> <td>15</td> <td>17</td> <td>14</td> <td></td> </tr> <tr> <td colspan="2">当前连对</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td></td> </tr> <tr> <td colspan="2">当前连错</td> <td>1</td> <td>4</td> <td>2</td> <td>4</td> <td>1</td> <td>7</td> <td>1</td> <td>2</td> <td>13</td> <td>3</td> <td></td> </tr> <tr> <td colspan="2">最大连对</td> <td>2</td> <td>1</td> <td>3</td> <td>1</td> <td>2</td> <td>1</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td></td> </tr> <tr> <td colspan="2">最大连错</td> <td>9</td> <td>7</td> <td>4</td> <td>12</td> <td>3</td> <td>7</td> <td>7</td> <td>4</td> <td>13</td> <td>3</td> <td></td> </tr> </table> </div> </div> </div> <script type="text/javascript" src="https://img.78500.cn/mobile/iscroll.js"></script> <script type="text/javascript"> var wrapper; function loaded() { wrapper = new iScroll("wrapper", { vScrollbar: false, hScrollbar: false, zoom: true, zoomMin: 0.5, zoomMax: 1 }); } document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('DOMContentLoaded', loaded, false); </script></body> </html> 对应上代码用正则表达式提取 以 <tr class="new"> 开头 </tr>结束 里面的数字
最新发布
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Knight-Key

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值