javascript - Is there a way to 'bake' the variable? -


i'm creating dynamic scroll page, decided use wheel event detect user's scrolling. may know event has deltay parameter updates dynamically(several times 1 scroll). want script return true once deltay bigger 100. updates on , on again causing function shoot several times. there way 'bake'(be able change once) true value?

window.addeventlistener('wheel', func)    function func(event){    if(event.deltay>100){      var p = document.createelement('p');      var text = document.createtextnode("you scrolled on 100");       p.appendchild(text);      document.body.insertbefore(p, document.getelementsbytagname('p')[0]);      }  }
<p>scroll page down \/ , keep scrolling</p>

you remove listener once element has been added. way function not continue fire.

window.addeventlistener('wheel', func)  function func(event){   if(event.deltay>100){     var p = document.createelement('p');     var text = document.createtextnode("you scrolled on 100");      p.appendchild(text);     document.body.insertbefore(p, document.getelementsbytagname('p')[0]);     window.removeeventlistener('wheel',func);     } } 

https://developer.mozilla.org/en-us/docs/web/api/eventtarget/removeeventlistener


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -