Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
jQuery: eventos múltiples, obtenga deltaY para un evento

Uso dos eventos ( scroll y mousewheel ).

Me gustaría obtener deltaY para el evento mousewheel para controlar un control deslizante.

La variable getDelta devuelve números e undefined a pesar de mi condición en el evento mousewheel .

Me gustaría obtener valores deltaY afuera.

¿Qué pasa, por favor? Gracias de antemano.

 $(window).on('scroll mousewheel', function(e) { if (e.type == "mousewheel") { var getDelta = e.deltaY; } console.log(getDelta); }

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

pones el registro de la consola fuera si la condición.

 $(window).on('scroll mousewheel', function(e) { var getDelta; if (e.type == "mousewheel") { getDelta = e.deltaY; } if(getDelta) { console.log(getDelta); }else{ console.log("delta is null"); } }
about 4 years ago · Juan Pablo Isaza Report

0

La mejor manera (en mi opinión) de hacer tus cosas con deltaY / X es usar detectores de eventos. Se pueden conectar y desconectar fácilmente, ya sea por acción humana o por algún activador automático generado por su aplicación/secuencia de comandos.

Coloque el código a continuación en una página web y verifique si está bien para usted.

 <script> // Getting delta trough event listeners // then passing them as parameters to be consumed by other function(s) function getDelta (e) // ... starting delta events capture { // We capture here both X and Y delta values (but you can use only deltaY) because // some mice may have left and right buttons on the scroll wheel // (Logitec g502 / Razer Basilisk / etc, ...) console.log(e.deltaX + ' <- left right || up down -> ' + e.deltaY); doSome(e.deltaY, e.deltaX); // ... the function which will consume events } function startDelta () { document.addEventListener('wheel', getDelta); } function stopDelta () // we stop deltaX and deltaY capture { document.removeEventListener('wheel', getDelta); } function doSome (y, x) // we pass events as arguments so we can use them { if (x > 0) console.log('some div with overflow will scroll left'); if (x < 0) console.log('some div with overflow will scroll right'); if (y > 0) console.log('some div with overflow will scroll up'); if (y < 0) console.log('some div with overflow will scroll down'); } </script> <button onclick="startDelta()"> Start Delta </button> &nbsp;&nbsp; <button onclick="stopDelta()"> Stop Delta </button>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!