Jump to content

JavaScript! Scrolling in div, how to set a handler(function) on event scrolling UP?

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
I need to set a function, for example
function ups() { alert("Scrolling UP"); }

on event SCROLLING UP in some div'element, how can I do it?

#2
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
HTML 5 introduced the onscroll event so if you don't need backward compatibility with ancient browsers that could be an option. Something like this Edit this Fiddle - jsFiddle - Online Editor for the Web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)

You could add timers to that code so that it doesn't show a popup for each little scroll but waits until the user has scrolled all he wants.

You could also look into jQuery which also seems to have a scroll event. Never used it though.

#3
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
I used scroll(); in JQuery, it's not what I need, I need to set a handler only on SCROLLING UP event!

#4
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
Have you checked the link I gave you? That has a working script that only alerts on scroll up.

The trick is to save the last scroll offset and compare it to the new one. If the new one is lesser than the old then it was a scroll up.

#5
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
Ohh, realy, I forgot click the link, there was a many words, I know fiddle, THANK YOU VERY MUCH BTW!

#6
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
Glad I could help!

If you manage to polish that script up maybe you could post your changes here so that those with the same question might benefit from it ;)

#7
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
****, I was glad very fast when it works on fiddle, but why It doesn't work on my site, any plagins/frameworks need or what?

#8
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
Nope. Just make sure you put that javascript code on the onload event of the body.

#9
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
Now it's finish! It was before onload event.
FIXED!!!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users