Reputation: 868
I'm not able to figure out how to assign a function to a scroll event in Dojo. I have seen this other post about using dojo's connect, but I've been unable to get that to work, and even if I could, my project's using behaviours as much as possible, so I'm really trying to get that to work first...
The puzzling thing for me, is that I've looked around on dojo's website a bit, and the only references I've seen to scroll events just mention them as an aside. On http://dojotoolkit.org/reference-guide/1.9/quickstart/events.html#connecting-to-a-dom-event as an example, there's a list of events that can be connect-ed to, and scroll isn't on them. Mouse wheel up + down are, but that does not cover all possible actions that might lead to a scroll occurring.
I've used jQuery's scroll event before, and that was nice and simple. The fact that I'm having this much trouble figuring out the scroll event in Dojo bothers me a little.
This is what I've tried:
var myBehavior = {
window : {
scroll: function(e) {
console.log("i'm scrolling");
}
}
};
behavior.add(myBehavior);
behavior.apply();
That loads without any problems, but scrolling doesn't give me the console logging message.
I've also tried
dojo.connect(window,'scroll',this,function() {
console.log("scrolling away");
})
which I pretty much got from the linked post, and I didn't get the console logging message either. I'm starting to wonder if I'm missing a key library?
The ones I have required that I think are more than necessary: - dojo/_base/lang - dojo/query - dojo/_base/event - dojo/on - dojo/behaviour - dojo/window
Does anybody have a suggestion for how I start registering these scrolling events in Dojo? Thank you
Upvotes: 0
Views: 2426
Reputation: 7852
I created a jsfiddle demoing the usage of dojo/on
for the window scroll event.
html:
<body>
<div style="height:1000px;">
Bacon ipsum dolor sit amet meatball drumstick jerky strip steak kielbasa shoulder, short ribs filet mignon prosciutto swine meatloaf ribeye tongue turkey andouille. Hamburger bacon fatback, short ribs pork loin cow chicken. Capicola venison andouille kielbasa cow. Short ribs kevin rump meatloaf jowl prosciutto leberkas. Pork belly shankle doner spare ribs, rump pork chop sausage tenderloin. Brisket swine pig, fatback beef ribs shank tri-tip flank ham venison strip steak filet mignon rump frankfurter ribeye.
Fatback turkey sausage tongue doner strip steak boudin shoulder chuck beef ribs chicken bacon brisket. Turkey biltong bacon cow short ribs fatback. Sausage brisket pork loin corned beef pork chop shank jowl capicola leberkas strip steak prosciutto beef tri-tip. Jowl frankfurter beef ribs, swine tail doner tri-tip t-bone. Jowl pork loin sausage venison salami shankle kevin strip steak boudin doner bresaola filet mignon ham drumstick ribeye. Turkey pork belly kielbasa ribeye salami, strip steak ham hock jerky shoulder tenderloin shankle spare ribs beef ribs filet mignon. Short loin fatback kevin, biltong tail shoulder ball tip.
Pork loin t-bone ground round tongue turducken tail shoulder chicken sausage pancetta hamburger, kielbasa tri-tip strip steak short ribs. Pork chop prosciutto tri-tip, jerky brisket leberkas andouille ham hock tongue shoulder fatback meatball. Pig short loin beef spare ribs, rump meatball short ribs doner kielbasa ball tip swine bacon kevin. Hamburger tail frankfurter ham hock tongue, jerky pork belly bacon shank salami prosciutto ground round doner jowl turducken. Prosciutto pork chop drumstick ham hock meatloaf. Drumstick ham hock ball tip salami cow.
Shankle hamburger sirloin sausage tongue pork chop flank, doner pig tri-tip pancetta shoulder. Venison ball tip beef biltong tail, corned beef pastrami andouille frankfurter kevin pork meatball chicken. Ground round shankle sirloin capicola kevin spare ribs ham hock fatback strip steak short ribs leberkas. Venison flank tenderloin tri-tip salami pork capicola drumstick brisket short ribs sirloin chuck boudin kielbasa cow.
Short ribs corned beef shankle meatball, tri-tip t-bone sirloin cow leberkas chicken jerky. Short loin drumstick pork loin biltong sausage prosciutto rump flank hamburger pork chop meatball capicola turkey leberkas cow. Andouille ribeye boudin ham chicken. T-bone rump meatball drumstick hamburger pork chop, flank sausage tongue andouille fatback.
Does your lorem ipsum text long for something a little meatier? Give our generator a try… it’s tasty!
</div>
</body>
js:
require(['dojo/on','dojo/domReady!'],function(on,domReadyPlugin){
on(window,'scroll',function(evt){
console.log(evt);
});
});
The result will print to the console every time the user scrolls in the window. If you continue to have issues with it, post more code so we can get to the bottom of it, this should be a simple thing to do.
Upvotes: 2
Reputation: 1516
use "onscroll" instead of "scroll", see this jsfiddle
dojo.connect(window,'onscroll',this,function() {
console.log("scrolling away");
})
Upvotes: 0