1

Is there a way to run a line of code after a marquee has finished scrolling its text one time? I was going to use it to whenever the text was gone I would remove the element in the queue index with the location of 0 and then use the marquee to show the next element in the queue. How would I do this?

I'm kinda new to coding, so please excuse me if this is a bad question to ask.

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];
Hitesh Tripathi
  • 856
  • 1
  • 11
  • 23
DerpehDoge
  • 11
  • 1
  • Hello @DerpehDoge. I like [this idea](https://stackoverflow.com/a/46677925/1865613) of Duc Filan. Just place an element inside the `` and check it's left position :) – ˈvɔlə Dec 04 '19 at 10:00

1 Answers1

0

as @WoIIe suggest you can check on the marquee element left position to find out if its finished scrolling, try doing somthing like this :

$(function () {
    var numberofCycles = 0;
    setInterval(function () {
        var currentLeft = $('#scrollText').position().left;
        if (currentLeft < 0 && numberofCycles == 0) {
            numberofCycles += 1;
            alert("One cycle finished!");
        }
    }, 100)
});
Voice Of The Rain
  • 495
  • 1
  • 8
  • 24