search

Home  >  Q&A  >  body text

Please give me some advice on how to monitor the mouse wheel event in js and then jump out of the currently running method.

Dear bosses:

I have a piece of js code that uses jquery’s animate method. I need to

monitor the movement of the mouse wheel when this code is running. If there is The movement of the mouse wheel will exit this animate method. Please tell me how to write the code?

Attachment:

window.onload = function () { setTimeout(autorollup,3000); function autorollup(){ $("#part2").animate( {top: "-=800px"}, 8000); }

Thank you for your enlightenment!

天空翱翔天空翱翔1221 days ago1063

reply all(4)I'll reply

  • 雪了无痕

    雪了无痕2021-11-10 11:19:58

    http://xf0c11m.cn/ Paipai.com View online

    reply
    0
  • autoload

    autoload2021-10-28 09:56:29

    Just add event listening, window.addEventListener("wheel", callback function);

    reply
    0
  • 天空翱翔

    Thanks! I mainly don't know how to add it to the code? How to write the callback function? Beginners can't write.

    天空翱翔 · 2021-10-28 17:12:59
    天空翱翔

    var StopscrollFunc=function(e){ e=e || window.event; if (e.wheelDelta || e.detail) {//Firefox //Custom event: write specific implementation logic $("#part2").stop(true); } } document.addEventListener('DOMMouseScroll',StopscrollFunc,false); If I write like this, the effect of mouse scrolling will be prevented indefinitely, because it is always listening. I need this monitoring to stop scrolling to run only once. How should I write the code? Thanks!

    天空翱翔 · 2021-10-28 17:17:55
  • Cancelreply