首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >始终在字幕中显示文本

问始终在字幕中显示文本
EN

Stack Overflow用户
提问于 2017-08-31 12:40:06
回答 3查看 939关注 0票数 0

我的目标是始终在我的标记字幕上显示没有空格的文本。文本应该总是出现在这个常见的动画中。

​

​

我的目标是始终在我的标记字幕上显示没有空格的文本。文本应该总是出现在这个常见的动画中。在我的实际项目中,我经常收到tweet,我将它们放在字幕中,我删除第一个,然后只要数量是5,我就创建一个.append (这不是一个好的解决方案,如果在一秒钟内有10条tweet到达,用户不能很好地阅读字幕。我希望在字幕内有5个跨度,在某一点上,我的网页开始变慢,因为不断执行.append并有许多跨度元素)。

使用设置的间隔,我模拟就像接收tweet一样,但在某一点上动画并不流畅,或者重新开始显示空格。我只想显示空格的首字母,否则我不想显示空格。

​

​

我不知道如何解决这个问题,也不知道是否有事件或其他事情可以检测第一个跨度何时离开容器,以便添加新元素并能够很好地读取选取框。

我已经尝试了几个库,但没有一个适合我的问题。

http://jsfiddle.net/fq2z6o99/

代码语言:javascript
复制
    <div id='container_marquee'>
     <marquee id='mymarquee' behavior="scroll" onmouseover="this.stop();" onmouseout="this.start();">
               <span>first marquee text</span>
               <span>second marquee text</span>
               <span>third marquee text</span>
               <span>fourth marquee text</span>
               <span>fifth marquee text</span>
     </marquee>
    </div>
EN

回答 3

Stack Overflow用户

发布于 2017-08-31 12:58:56

使用选框行为= alternate。

票数 0
EN

Stack Overflow用户

发布于 2017-08-31 14:53:41

我已经动态添加了第六个字幕文本。尝试如下所示:

​

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type='text/javascript' src='//cdn.jsdelivr.net/jquery.marquee/1.4.0/jquery.marquee.min.js'></script>
<style>
.marquee {
  width: 300px;
  overflow: hidden;
  border: 1px solid #ccc;
  background: #ccc;
}
.marquee span{
	margin:0 15px;
}
</style>
</head>
<body>
<div class="marquee">
	<span>first marquee text</span>
	<span>second marquee text</span>
	<span>third marquee text</span>
	<span>fourth marquee text</span>
	<span>fifth marquee text</span>
</div>
</body>
<script>
$('.marquee').marquee({
    //speed in milliseconds of the marquee
    duration: 5000,
    //gap in pixels between the tickers
    gap: 50,
    //time in milliseconds before the marquee will start animating
    delayBeforeStart: 100,
    //'left' or 'right'
    direction: 'left',
    //true or false - should the marquee be duplicated to show an effect of continues flow
    duplicated: true
});
$(".marquee span:last-child").after("<span>Sixth marquee text</span>");
</script>
</html>

​

票数 0
EN

Stack Overflow用户

发布于 2017-08-31 18:10:54

您可以编写自定义jQuery代码来替换选框标签。

试试下面的代码可能会对你有帮助:

代码语言:javascript
复制
<html>
<head>
<style>
* {
    margin:0; padding:0
}
div {
    background: white;
    width: 600px;
    height: 40px;
    border: 2px solid red;
}
div p {
    position: relative;
}
</style>
</head
<body>
<div>
    <p>Lorem ipsum dollar sit, lorem ipsum dollar</p>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var animation = function() {
    $('div p').animate({left: '320'}, 5000,

    function() {
        $('div p').animate({left: '0'}, 5000);
        animation();
    });
};

animation();

</script>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45973344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档