Marquee3000 icon indicating copy to clipboard operation
Marquee3000 copied to clipboard

Destroying the instance

Open arnasziedavicius opened this issue 7 years ago • 9 comments

Great little script!

Was wondering if there's a way to destroy the instance?

I have a situation where Marquee3k keeps initialising and as a consequence accelerating the speed.

arnasziedavicius avatar Jun 22 '17 08:06 arnasziedavicius

Same problem. I found a way of preventing it by giving an id to the animation frame : Line 141 : animationId = window.requestAnimationFrame(animate);

Then kill it on init : Line 124 : window.cancelAnimationFrame(animationId);

tristantbg avatar Jul 01 '17 10:07 tristantbg

Thank you @tristantbg, this works like a charm. Any chance of adding this to a pull request?

pbridi avatar Sep 25 '17 21:09 pbridi

not work for me, get an Uncaught ReferenceError: animationId is not defined @pbridi @tristantbg

thibaudallie avatar Jan 21 '18 12:01 thibaudallie

@tibuakaw Have you declared the animationId variable?

ernestobellei avatar Apr 25 '18 09:04 ernestobellei

hi! trying to implement the animationId trick as well, but not working. Here the complete code:

static init(options = { selector: 'marquee3k' }) {
      var animationId; // set variable
      window.cancelAnimationFrame(animationId); // kill it;
      window.MARQUEES = [];
      const marquees = Array.from(document.querySelectorAll(`.${options.selector}`));
      let previousWidth = window.innerWidth;
      let timer;

      for (let i = 0; i < marquees.length; i++) {
        const marquee = marquees[i];
        const instance = new Marquee3k(marquee, options);
        MARQUEES.push(instance);
      }

      animate();

      function animate() {
        for (let i = 0; i < MARQUEES.length; i++) {
          MARQUEES[i].animate();
        }
        animationId = window.requestAnimationFrame(animate); // save values to variable
      }

i'm doing this on a js-spa website, and any time i'm mounting / unmounting a component the speed of the marquee keeps increasing.

am i setting the variable at the wrong place?

thanks, af

sonn-gamm avatar Feb 15 '19 14:02 sonn-gamm

hi! trying to implement the animationId trick as well, but not working. Here the complete code:

static init(options = { selector: 'marquee3k' }) {
      var animationId; // set variable
      window.cancelAnimationFrame(animationId); // kill it;
      window.MARQUEES = [];
      const marquees = Array.from(document.querySelectorAll(`.${options.selector}`));
      let previousWidth = window.innerWidth;
      let timer;

      for (let i = 0; i < marquees.length; i++) {
        const marquee = marquees[i];
        const instance = new Marquee3k(marquee, options);
        MARQUEES.push(instance);
      }

      animate();

      function animate() {
        for (let i = 0; i < MARQUEES.length; i++) {
          MARQUEES[i].animate();
        }
        animationId = window.requestAnimationFrame(animate); // save values to variable
      }

i'm doing this on a js-spa website, and any time i'm mounting / unmounting a component the speed of the marquee keeps increasing.

am i setting the variable at the wrong place?

thanks, af

Just write in unmounting function window.MARQUEES = null

GoAndrew avatar Feb 27 '19 15:02 GoAndrew

var animationId; //

@tibuakaw @GoAndrew @afincato

you are creating local variable, that will reassigned to undefined every-time if you call init(). So please create as global variable window.animationId like and do it at top of the library. I am sure it will work.

if(window.animationId){ window.cancelAnimationFrame(window.animationId); }

muni2explore avatar Mar 08 '19 02:03 muni2explore

@muni2explore thanks that worked!

sonn-gamm avatar Mar 18 '19 11:03 sonn-gamm

Just made a pull request with set animation ID as per @tristantbg comment: https://github.com/ezekielaquino/Marquee3000/pull/25

arnasziedavicius avatar Oct 22 '19 17:10 arnasziedavicius