选取框滚动一次后,是否可以运行一行代码?

时间:2019-12-04 06:05:48

标签: javascript html marquee

字幕框一次滚动完成其文本后,是否可以运行一行代码?每当文本消失时,我都会用它来删除队列索引中位置为0的元素,然后使用选取框显示队列中的下一个元素。我该怎么办?

我对编码有点陌生,所以请问这是一个不好的问题。

let scroller = document.getElementById("scrollText")

let news = function (news, id) {
  this.text = news;
  this.id = id;
}

let newsFeed = [
  new news("Bob has slipped and fell once again. Oh dear.", 1),
  new news("Alicia has lost her keys.", 2)
]

let queue = []
scroller.innerHTML = queue[0]
queue.append(newsFeed[Math.round(math.random) * newsFeed.length])

//Whenever the marquee is done scrolling

queue.pop()
scroller.innerHTML = queue[0];

1 个答案:

答案 0 :(得分:0)

@WoIIe建议您可以检查选取框元素的左侧位置,以了解滚动是否完成,请尝试执行以下操作:

$(function () {
    var numberofCycles = 0;
    setInterval(function () {
        var currentLeft = $('#scrollText').position().left;
        if (currentLeft < 0 && numberofCycles == 0) {
            numberofCycles += 1;
            alert("One cycle finished!");
        }
    }, 100)
});
相关问题