网页自动滚屏播放

好长时间不做网页了,今天老板说要做一个展示的demo,让这个demo 自动的播放

用js做了一个滚屏播放的代码

<script type="text/javascript">
        var done = true;
        var speed = 4         //设置速度
        var currentpos = 0, alt = 1, curpos1 = 0, curpos2 = -1
        function initialize() {
            startit()
        }
        function scrollwindow() {

            if (done) {
                if (document.all)
                    temp = document.body.scrollTop
                else
                    temp = window.pageYOffset
                if (alt == 0)
                    alt = 1
                else
                    alt = 0
                if (alt == 0)
                    curpos1 = temp
                else
                    curpos2 = temp
                if (curpos1 != curpos2) {
                    if (document.all)
                        currentpos = document.body.scrollTop + speed
                    else
                        currentpos = window.pageYOffset + speed
                    window.scroll(0, currentpos)
                }
                else {
                    currentpos = 0
                    window.scroll(0, currentpos)
                }
            }
        }
        function startit() {
            setInterval("scrollwindow()", 1000)
        }
        function setDone(f) {
            if (f == 0) {
                done = false;
        
            }
            if (f == 1) {
                done = true;
            }
        }
        window.onload = initialize
    </script>

在上面的这段代码中,我有添加了一个点击停止播放的函数function setDone(f),这个函数可以加到按钮上来控制是否自动播放

例如:

<span style="font-size: 10pt; color: white;" οnclick="setDone(1)">自动 </span>

  

 

转载于:https://www.cnblogs.com/xiaopanlyu/p/4822126.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QTextEdit自动滚屏的实现可以通过使用QTextCursor来定位内容的最后位置,并在每次内容更新信号发送后移动光标。下面是一个简单的例子: ```cpp #include <QTextEdit> #include <QTimer> class TextEdit : public QTextEdit { Q_OBJECT public: TextEdit(QWidget *parent = 0); ~TextEdit(); private: QTimer *timer; public slots: void addText(); void autoScroll(); }; TextEdit::TextEdit(QWidget *parent) : QTextEdit(parent) { timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(addText())); connect(this, SIGNAL(textChanged()), this, SLOT(autoScroll())); } void TextEdit::addText() { // 添加新的文本内容 // ... // 移动光标到最后位置 QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::End); setTextCursor(cursor); } void TextEdit::autoScroll() { // 自动滚动到最后位置 verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } ``` 在这个例子中,我们创建了一个名为TextEdit的自定义QTextEdit类。在构造函数中,我们创建了一个定时器timer,并将其与addText()槽函数连接。addText()槽函数用于添加新的文本内容,并将光标移动到最后位置。我们还将textChanged()信号与autoScroll()槽函数连接,autoScroll()槽函数用于自动滚动到最后位置。 通过使用这个自定义的TextEdit类,你可以实现QTextEdit的自动滚屏功能。 #### 引用[.reference_title] - *1* *2* *3* [Qt4小技巧——QTextEdit自动滚屏](https://blog.csdn.net/a13393665983/article/details/102189035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值