简体   繁体   English

使用JavaScript函数进行水平文本滚动?

[英]Horizontal text scrolling with JavaScript function?

I currently have a text box with some default text in it. 我目前有一个文本框,其中包含一些默认文本。 When a button is clicked, the text is changed. 单击按钮后,文本将更改。 Is it possible to have the new text scrolling? 是否可以滚动新文本? I've looked at marquee but it seems it doesn't have good rep, and I'm not sure how to incorporate it with JavaScript. 我已经看过字幕,但它似乎没有很好的代表,而且我不确定如何将其与JavaScript结合。 Here's the coding I have: 这是我的编码:

HTML text box: HTML文本框:

<tr>
    <td colspan="4" class="message">
        <p class="displaymessage">
             <marquee behavior="scroll" direction="left">innterHTML Page</marquee>
        </p>
    </td>
</tr>

(this currently scrolls the default text) (当前滚动默认文本)

HTML Button: HTML按钮:

<input type="button" value="1" class="button" onClick="changeText1()">

Javascript: Javascript:

function changeText1() {

     var paragraph = document.getElementsByClassName('displaymessage');

     var changeText = paragraph[0].innerHTML = "New text";
}

Any suggestions? 有什么建议么? Thanks 谢谢

I don't understand what you want to do. 我不明白你想做什么。 But if you want to add new text and want to scroll it left as your previous text is scrolling ie ** innterHTML Page** then you can use the following code in javascript:- 但是,如果您想添加新文本并希望在上一个文本滚动时向左滚动(即** innterHTML Page **),则可以在javascript中使用以下代码:

   function changeText1() {

var paragraph = document.getElementsByClassName('displaymessage');

var changeText = paragraph[0].innerHTML = '<marquee behavior="scroll" direction="left">New text Here</marquee>';

}

It will work Fine. 它将正常工作。 If you have any questions you can comment :) 如果您有任何问题可以发表评论:)

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

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