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

439
Views
¿Diferenciar entre desplazarse hacia arriba/abajo en jquery?

He encontrado algunas maneras excelentes de verificar dónde está la barra de desplazamiento usando jquery, pero me preguntaba si puede diferenciar si el usuario se desplazó hacia arriba o hacia abajo.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Compruebe el último estado. Algo como esto:

Mantenga una variable, digamos, last_scroll_position , y cuando tenga un desplazamiento, si last_scroll_position - current_position > 0 , el usuario se desplazó hacia arriba y hacia abajo si es menor que 0.

over 4 years ago · Santiago Trujillo Report

0

<script type='text/javascript'> $(function(){ var CurrentScroll = 0; $(window).scroll(function(event){ var NextScroll = $(this).scrollTop(); if (NextScroll > CurrentScroll){ //write the codes related to down-ward scrolling here } else { //write the codes related to upward-scrolling here } CurrentScroll = NextScroll; //Updates current scroll position }); });

over 4 years ago · Santiago Trujillo Report

0

Para diferenciar entre desplazarse hacia arriba/abajo en jQuery, puede usar:

 var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x $('#yourDiv').bind(mousewheelevt, function(e){ var evt = window.event || e //equalize event object evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible var delta = evt.detail ? evt.detail*(-40) : evt.wheelDelta //check for detail first, because it is used by Opera and FF if(delta > 0) { //scroll up } else{ //scroll down } });

Este método también funciona en divs que tienen overflow:hidden .

Lo probé con éxito en FireFox, IE y Chrome.

over 4 years ago · Santiago Trujillo 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!