0

How can I show the alert when I have scrolled to the right 300px?

$('.container').scroll(function () {
    if ($(this).scroll() === 300) { //
        alert("You've scrolled 300 pixels.");
    }
});

Can I get some help getting a callback without using jquery?

Joseph
  • 117,725
  • 30
  • 181
  • 234
Josh
  • 605
  • 2
  • 8
  • 16
  • 1
    See this for binding events in JavaScript -> http://stackoverflow.com/questions/1796141/properly-bind-javascript-events – Manse Mar 01 '13 at 15:39
  • If you can do it with jquery, then you can *always* do it with pure javascript. It's just likely to be more difficult. A better title would probably be "How can this be done without jquery?" – joelmdev Mar 01 '13 at 17:32

2 Answers2

0

You can bind to the onscroll method:

window.onscroll = function() {
    if (window.pageYOffset == 300) {
        alert("You've scrolled 300 pixels.");
    }
};
CassOnMars
  • 6,153
  • 2
  • 32
  • 47
0

You can use the onscroll event just like the onclick on element.

Gus
  • 6,719
  • 6
  • 37
  • 58
Vijay Verma
  • 3,660
  • 2
  • 19
  • 27