简体   繁体   English

动态添加文本到 jQuery 选框

[英]dynamically add text to jQuery marquee

How to add text in jquery marquee dynamically?如何在 jquery 字幕中动态添加文本?

I have tried to append the text to a marquee, it's working but when I add long text, it starts not working properly (The text marquee didn't finish in the middle of animation marquee will be started again even the last text hasn't arrived yet).我尝试将 append 文本添加到选框,它正在工作,但是当我添加长文本时,它开始无法正常工作(文本选框在 animation 中间没有完成,即使最后一个文本还没有完成还没到)。

my code like this:我的代码是这样的:

 $(document).ready(function(){ $('.marquee').marquee({ //speed in milliseconds of the marquee duration: 15000, //gap in pixels between the tickers gap: 50, //time in milliseconds before the marquee will start animating delayBeforeStart: 0, //'left' or 'right' direction: 'left', //true or false - should the marquee be duplicated to show an effect of continues flow duplicated: true }); }); function AppendData(){ document.getElementById("line").innerHTML += '| MARK | ------------------------------------ THIS IS LONG TEXT I APPEND -------------------------------------------------------------------'; }
 .marquee { width: auto; overflow: hidden; }.marquee span.line{ padding-top: 6px; color: rgba(0,0,0, 0.6); font-size: 9pt; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="//cdn.jsdelivr.net/npm/jquery.marquee@1.5.0/jquery.marquee.min.js" type="text/javascript"></script> <div class="marquee" id="tambah"> <span class="line" id="line"><span class="title">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span> </div> <button onclick="AppendData()">Add Text</button>

Marquee.js seems to be really futsy. Marquee.js 似乎真的很无聊。 This should get you close to where you'd like to be.这应该让你接近你想去的地方。 I can't keep working on it, but I wanted to at least put you in the right direction.我不能继续努力,但我想至少让你朝着正确的方向前进。 Before its invocation, you can .bind() an event called finished that will destroy the old marquee, reset data, and resume the marquee.在调用它之前,您可以.bind()一个名为finished的事件,该事件将销毁旧的选取框、重置数据并恢复选取框。 However, there doesn't seem to be any looping options that don't make it restart from the right of the screen, so it jumps.但是,似乎没有任何循环选项不会使其从屏幕右侧重新启动,因此它会跳转。 I'm sure there's something you can do with this.我敢肯定你可以用这个做点什么。 Please look at the event part of Marquee.js' documentation for more info.请查看 Marquee.js 文档的事件部分以获取更多信息。

https://github.com/aamirafridi/jQuery.Marquee#events https://github.com/aamirafridi/jQuery.Marquee#events

 $(document).ready(function() { const options = { //speed in milliseconds of the marquee duration: 2000, //gap in pixels between the tickers gap: 50, //time in milliseconds before the marquee will start animating delayBeforeStart: 0, //'left' or 'right' direction: 'left', //true or false - should the marquee be duplicated to show an effect of continues flow duplicated: true }; const textToAdd = '| MARK | ------------------------------------ THIS IS LONG TEXT I APPEND -------------------------------------------------------------------'; var addLine = false; const line = $("#line"); const btn = $("#btn"); $('.marquee').bind('finished', function() { if (addLine == true) { var newLine = $("#line").innerHTML += textToAdd; $(this).marquee('destroy').append(newLine); $('.marquee').marquee(options); } }).marquee(options); btn.on("click", function appendData() { addLine = true; }); });
 .marquee { width: auto; overflow: hidden; }.marquee span.line { padding-top: 6px; color: rgba(0, 0, 0, 0.6); font-size: 9pt; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="//cdn.jsdelivr.net/npm/jquery.marquee@1.5.0/jquery.marquee.min.js" type="text/javascript"></script> <div class="marquee" id="tambah"> <span class="line" id="line">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span> </div> <button id="btn">Add Text</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM