Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Mouse scroll start animation

Community Beginner ,
Oct 11, 2018 Oct 11, 2018

Hello I need very simple function but can`t find any info for it:

i need on mouse scroll down / up to start function where animations load - is that possible?

Thanks 

634
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 11, 2018 Oct 11, 2018

You can try something like this:

function onMouseWheel(e)

{

    if (this.anim.currentFrame == 0)

          this.anim.play();

}

document.getElementById('canvas').addEventListener('mousewheel', onMouseWheel.bind(this));

document.getElementById('canvas').addEventListener('DOMMouseScroll', onMouseWheel.bind(this));

Regards,

JC

Translate
Community Expert ,
Oct 11, 2018 Oct 11, 2018

Hi.

AS3 or HTML5?

And do you need the animation to keep playing while the mouse wheel is being rotated or do you need the animation to only play once?

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2018 Oct 11, 2018

Hello, HTML5 , I need just one to be started. Both scroll down and up

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2018 Oct 11, 2018

You can try something like this:

function onMouseWheel(e)

{

    if (this.anim.currentFrame == 0)

          this.anim.play();

}

document.getElementById('canvas').addEventListener('mousewheel', onMouseWheel.bind(this));

document.getElementById('canvas').addEventListener('DOMMouseScroll', onMouseWheel.bind(this));

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 11, 2018 Oct 11, 2018

WOW! thanks a lot. is there a way to define if "scroll down" or "scroll up" ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 11, 2018 Oct 11, 2018

Sure.

Try this:

function onMouseWheel(e)

{

    var delta;

  

    // we have to check what kind of property is available depending on the browser the page is running

    if (e == window.event)

          delta = -10 / window.event.wheelDeltaY;

    else

          delta = e.detail / 30;

    if (delta < 0)

    {

          if (this.anim.currentFrame == 0)

              this.anim.play();

    }

    else

    {

          if (this.anim1.currentFrame == 0)

              this.anim1.play();

    }

}

document.getElementById('canvas').addEventListener('mousewheel', onMouseWheel.bind(this));

document.getElementById('canvas').addEventListener('DOMMouseScroll', onMouseWheel.bind(this));

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 12, 2018 Oct 12, 2018

Thanks a lot mate - that works great!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2018 Oct 12, 2018
LATEST

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines